Restoring a database backup is not a straight forward thing when it comes to Docker Container Images.
If you have a database backup and you want to restore it to your SQL Docker Container Image , you need to follow the below steps
- Pull the Docker Image from Docker container.
docker pull microsoft/mssql-server-windows-developer:2017
- After your image download has been completed you can start your SQL Server image
PS C:\> docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=P@ssw0rd" -p 1433:1433 --name sql1 -d microsoft/mssql-server-windows-developer
- To get the IP address of your Docker image you can run:
docker inspect --format '{{.NetworkSettings.Networks.nat.IPAddress}}' sql1
If you wish to change the IP address of your docker image, follow the below link
- Now your SQL Docker Image must be up and running. Connect it using SSMS.
- To Restore the existing database backup to docker image,follow the below steps
- op the running docker Image using the below command
Docker Stop <Image Name> Docker Stop SQL1 OR DOCKER STOP <Container ID> You can get the container ID by runnning Docker ps -a PS C:\> docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 59c75b5e9809 microsoft/mssql-server-windows-developer "powershell -Command…" 13 hours ago Up 30 minutes (healthy) 0.0.0.0:1433->1433/tcp sql1 Docker Stop 59c75b5e9809
- Now Copy the database backup file into docker image
docker cp C:\SQLContainerDB\DockerSqlDB.BAK sql1:c:\DockerSqlDB.BAK
- Start the image after the backup file is copied
Docker start <Image Name> or <Container Id>
- Connect to the SQL Image using SSMS and try to restore the database backup
Once the Database is restored , you can start using it. All changes made to the database will be auto committed as its part of the image. But on Linux you need to commit the change to the Docker Image, else all changes will be lost.