Home > OS >  Why docker with SQL Server disappeared?
Why docker with SQL Server disappeared?

Time:01-05

I run SQL Server in container

docker run --network=bridge --name sql29 -h sql29 -it --rm -v h:/sql219data:/var/opt/mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=sQL_19[pwd]" -p 12433:1433 -d mcr.microsoft.com/mssql/server:2019-latest

as described here: https://docs.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15

I see the active docker

docker ps

But if I try to create the new folder :

docker exec -it sql29 mkdir /var/opt/mssql/bkp22

then the docker disappeared.

docker ps
.........

How to understand: why the docker disappeared? Maybe the volume was mapped incorrectly?

CodePudding user response:

As @Zeitounator commented, the tutorial you linked has a note saying that bind mounts don't work on Windows with the /var/opt/mssql directory:

Host volume mapping for Docker on Windows does not currently support mapping the complete /var/opt/mssql directory. However, you can map a subdirectory, such as /var/opt/mssql/data to your host machine.

You commented that your goal was to keep or restore databases between docker runs. You don't need a bind mount to do that, this is the primary purpose of a volume. You can create a volume using docker volume create:

docker volume create sql219data

Then run your container using this volume:

docker run -v sql219data:/var/opt/mssql # ...

For debugging purposes you can remove the --rm option from your docker run command so the container won't be removed when stopped. You will then be able to read the logs of the container (even if it stopped):

docker logs sql29
# Then remove it to run the same `docker run` command again
docker rm sql29
docker run # ...
  •  Tags:  
  • Related