I created a Docker image of SQL Server with my databases. It works fine when I don't map to persist data, but when I map my databases are missing (the default databases are there).
I pulled mcr.microsoft.com/mssql/server:2019-latest and restored my database (TestDatabase) from a backup. Then I paused the container, did a docker commit, and tagged the image as mydatabase.
Then I start a container using this command:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=P@ssword123" -p 14350:1433 -d mydatabase
When I connect to this SQL Server, I see my database and tables. I open a terminal and go to /var/opt/mssql/data, and I see my database files:
TestDatabase.ldf
TestDatabase.ldf.mdf
I stop the container, and restart it with /var/opt/mssql/data mapped using this command:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=P@ssword123" -p 14350:1433 --mount type=bind,source=C:\Users\me\testing\mssql\data,target=/var/opt/mssql/data -d mydatabase
When I connect to the database I don't see my new database.
When I list /var/opt/mssql/data in the terminal window, I don't see my database files.
On my local filesystem the mapped location (C:\Users\me\testing\mssql\data) has been created, and it has default SQL Server database but not my database files.
As a double check, I go back to the container without the mount and I see my imported database.
If I had the mapping syntax wrong, I wouldn't have any of the files.
I have used this same process for other images and it works fine. This is the first image I created after upgrading docker to Docker Desktop version 4.12.0.
This is running on Windows, and here is my docker version info:
PS C:\WINDOWS\system32> docker version
Client:
Cloud integration: v1.0.29
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:09:02 2022
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.12.0 (85629)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:23 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Update: To see the databases in my instance I run:
SELECT name
FROM sys.databases;
When not mapping I get:
master
tempdb
model
msdb
MyDatabase
When mapping to I get:
master
tempdb
model
msdb
It seems that when I mount I am getting the default version of the files before I did the commit. When I don't mount, I get the commited image.