liveBook · Manning

Docker volume

As explained in 100 SQL Server Mistakes and How to Avoid Them

A Docker volume is a Docker-managed persistent storage resource whose data resides outside a container's writable layer.

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

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines volumes, explains host placement and driver choices, and demonstrates creation and container mapping commands.
Examples
Uses the sqldata volume and a SQL Server 2022 container mapped to /var/opt/mssql.
What it assumes
Assumes Docker is installed and running and the default SQL Server 2022 container image is available.
What you can do after
Operate/configure a SQL Server container with persistent storage using Docker volume and run commands.
How it connects
Connects Docker volumes with SQL Server containers, Docker CLI management, host directories, and external storage drivers.

Also explained in

Compare how 4 books explain Docker volume →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.