简体   繁体   English

SQLServer 容器在停止时丢失数据,尽管它已安装到卷

[英]SQLServer Container looses Data when stopped although it is mounted to volume

please bear in mind this is my first time posting here I might not know all the rules and stuff.请记住,这是我第一次在这里发帖,我可能不知道所有的规则和东西。

so I have just started working with dockers and images.所以我刚刚开始使用码头工人和图像。 I created a small.Net app and I used MsSQLServer docker image in my app.我创建了一个 small.Net 应用程序,并在我的应用程序中使用了 MsSQLServer docker 图像。 The app gets connected with the server and I am able to create database using CodeFirst approach (add-migration and update database works fine).该应用程序与服务器连接,我能够使用 CodeFirst 方法创建数据库(添加迁移和更新数据库工作正常)。

i am running my SQL container with -rm mode.我正在使用 -rm 模式运行我的 SQL 容器。 Although it has a volume mounted to it but i have to create database every time i rerun the container.虽然它安装了一个卷,但每次重新运行容器时我都必须创建数据库。 I read that if we want our data not to get lost when we delete the container we have to mount volumes to our container.我读到如果我们希望我们的数据在删除容器时不会丢失,我们必须将卷安装到我们的容器中。 i had done the same thing using MongoDb docker image and it worked fine.我使用 MongoDb docker 图像做了同样的事情,效果很好。 my data is still present even when i stop and rerun my MongoContainer.即使我停止并重新运行 MongoContainer,我的数据仍然存在。 but my MSSQL is unable to retain data.但我的 MSSQL 无法保留数据。 here is the command im using to run my docker image ( i know about docker-compose but i am avoiding using it for now)这是我用来运行我的 docker 图像的命令(我知道 docker-compose,但我暂时避免使用它)

docker run -d --rm --name mssqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e MSSQL_SA_PASSWORD=********** -v sqlData:/data/db  mcr.microsoft.com/mssql/server

Note: this says it will not delete named volume with --rm https://docs.docker.com/engine/reference/run/#clean-up---rm注意:这表示它不会使用 --rm https://docs.docker.com/engine/reference/run/#clean-up---rm删除命名卷

The path you mount the volume on is a Linux path, so you need to use forward slashes rather than back-slashes, like this您安装卷的路径是 Linux 路径,因此您需要使用正斜杠而不是反斜杠,像这样

docker run -d --rm --name mssqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e MSSQL_SA_PASSWORD=********** -v sqlData:/var/opt/mssql mcr.microsoft.com/mssql/server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM