Question

I am testing out a POC project for SQL on Docker containers on Linux and wanted some background info on how to request the storage on the Linux VM. The plan is to spin up 10 containers with SQL 2019 on storage of at least 10 TB

My question is specific to where the sql containers are stored within the Linux VM. This will help me to request storage capacity for that specific mount point accordingly

Thank you

Was it helpful?

Solution

When running SQL Server in a container you'll want to use either bind mounts or named volumes to persist the databases.

By using either bind mounts or named volumes what you're doing is separating out the data from the SQL instance so that if a container has an issue and needs to be removed, you can spin up another one and mount the databases into it.

Bind mounts are mounting volumes from the host into the container and named volumes are volumes created within docker that can be mapped from one container to another.

Both are specified by using the --volume flag in the docker container run statement.

By using these you can determine where on the host the SQL Server databases will persist and request storage accordingly.

An example of bind mounts: -

mkdir /mnt/mssqlsystem
mkdir /mnt/mssqluser

docker container run -d \
--publish 1433:1433 \
--volume /mnt/mssqlsystem:/var/opt/mssql/data \
--volume /mnt/mssqluser:/var/opt/sqlserver \
--env ACCEPT_EULA=Y \
--env MSSQL_SA_PASSWORD=Testing1122 \
--env MSSQL_DATA_DIR=/var/opt/sqlserver \
--env MSSQL_LOG_DIR=/var/opt/sqlserver \
--name sqlcontainer1 \
mcr.microsoft.com/mssql/server:2019-CU6-ubuntu-18.04

What's happening here is that two directories have been created on the host and mapped to /var/opt/mssql/data (the location of the system databases) and /var/opt/sqlserver within the container. /var/opt/sqlserver is also the default location for the user data and log directories set by ENV variables.

An example of named volumes: -

docker volume create mssqlsystem
docker volume create mssqluser

docker container run -d \
--publish 1433:1433 \
--volume mssqlsystem:/var/opt/mssql \
--volume mssqluser:/var/opt/sqlserver \
--env ACCEPT_EULA=Y \
--env MSSQL_SA_PASSWORD=Testing1122 \
--env MSSQL_DATA_DIR=/var/opt/sqlserver \
--env MSSQL_LOG_DIR=/var/opt/sqlserver \
--name sqlcontainer1 \
mcr.microsoft.com/mssql/server:2019-CU6-ubuntu-18.04

Here two named volumes are created and mapped to /var/opt/mssql/data and /var/opt/sqlserver within the container. You don't actually need to individually create the volumes, if they're specified in the docker container run statement and don't already exist, docker will create them.

You can see the location of the named volume on the host by running

docker volume inspect mssqlsystem
docker volume inspect mssqluser

The location where named volumes are created can be altered by using a docker volume plugin. More details are here: - https://dbafromthecold.com/2018/05/02/changing-the-location-of-docker-named-volumes/

Full run throughs of using bind mounts and named volumes are detailed in The SQL Server and Containers guide here: - https://github.com/dbafromthecold/SqlServerAndContainersGuide/wiki

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top