I need a few help on the below mentioned issue.
I am creating a container for SQL server image on windows. I created a sample test database on the SQL server. After I restart or quit from the docker the container gets exited and the SQL data gets lost.
How can I maintain the persistence of the SQL database and table even after restarting or removing the docker container.
Steps to reproduce the behavior
- Created a container and saved the backup .mdf file in local folder.
docker run --name testcontainer1 -d -p 15799:1433 -v D:\SQLServer:C:\SQLServer -e sa_password=******* -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
Created a test database and test table in the SQL container.
Stopped and removed the running container with the below command
docker stop testcontainer1
docker rm testcontainer1
Created another container,
docker run -d -p 15799:1433 -v D:\SQLServer:C:\SQLServer --env ACCEPT_EULA=Y --env sa_password=****** --name testcontainer2 microsoft/mssql-server-windows
- Attached the backup .mdf file inside this container and I got back the database and table.
How can I maintain the pesistence of data in SQL container when i deploy my application in a production environment even after stopping or removing the container.