Mistake 1: treating a SQL Server container as a permanent server. Containers are stateless; removing one without external persistence loses everything inside it, including databases and code. section 8.3
A Docker volume is a Docker-managed resource that points to a filesystem location outside the container. The SQL Server instance runs in the container, while the volume keeps its data on the host. section 8.3
Use a volume deliberately:
- Map SQL Server's data directory to the volume when creating the container. section 8.3
- Prefer Docker volumes over direct host-directory mounts when Docker CLI management, migration, or sharing between containers matters. section 8.3
- Remember that the built-in local driver stores the volume on the host; other drivers can place volumes on external storage. section 8.3
A recoverable SQL Server container
A development team can remove and recreate its SQL Server container without discarding its databases, provided the container maps /var/opt/mssql to a Docker volume such as sqldata. section 8.3
Listing 8.1 Creating a Docker volume
sudo docker volume create sqldata
Create the named sqldata volume before starting the SQL Server container. section 8.3
Listing 8.2 Creating a SQL Server container using a Docker volume
sudo docker run -e "ACCEPT_EULA=Y" \ -e "MSSQL_SA_PASSWORD=Pa$$w0rd" \ -p 1433:1433 \ --name production \ --hostname production \ -v sqldata:/var/opt/mssql \ -d mcr.microsoft.com/mssql/server:2022-latest
Start SQL Server 2022 and map its data directory to sqldata. section 8.3



