Sql-docs: Adding volume breaks SQL Server container on linux

Created on 19 Feb 2020  Â·  3Comments  Â·  Source: MicrosoftDocs/sql-docs

Referring to "Persisting your data" section: Is anyone encountering such problem? I'm trying to run sqlserver container on Linux machine. Using volume to persist database contents outside of container results with some strange errors.

Here is docker-compose output of sqlserver container called db:

db_1            | SQL Server 2019 will run as non-root by default.
db_1            | This container is running as user mssql.
db_1            | To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
db_1            | 2020-02-19 13:56:21.67 Server      Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-02-19 13:56:21.78 Server      ERROERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x80070002)
R: Setup FAILED copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf':  2(The system cannot find the file specified.)
webserver_db_1 exited with code 1

Here is my docker-compose:

version: '3.4'
services:
  db:
    image: "mcr.microsoft.com/mssql/server"
    environment:
      SA_PASSWORD: "[some password]"
      ACCEPT_EULA: "Y"
    ports:
      - 1433:1433 # port for management
    volumes:
      - ./__database__:/var/opt/mssql/data # db data 

Database works fine if I comment out 2 last lines (remove "volumes" section).


Document Details

âš  Do not edit this section. It is required for docs.microsoft.com âžź GitHub issue linking.

Pri1 assigned-to-author doc-bug linutech sqprod

Most helpful comment

I have the same issue with the https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#persist section

Two things give the container a name, and change the scropt so it works:

Example of failed code

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Th1sIsStr0ng' \
-p 1408:1433 --name sql8 \
-v /db/data:/var/opt/mssql/data \
-v /db/log:/var/opt/mssql/log \
-v /db/secrets:/var/opt/mssql/secrets \
-d mcr.microsoft.com/mssql/server:2019-latest

Get

darwin@spokeDockerVM:/$ docker logs sql8
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
2020-03-09 22:15:24.28 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-03-09 22:15:24.41 Server ERROR: Setup FAILED copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf': 2(The system cannot find the file specified.)
ERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x80070002)
darwin@spokeDockerVM:/$

Here is how I fixed it:

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=fakePassw0rd' \
-u 0:0 -p 1407:1433 --name sql7 \
-v /home/darwin/database/data:/var/opt/mssql/data \
-v /home/darwin/database/log:/var/opt/mssql/log \
-v /home/darwin/database/secrets:/var/opt/mssql/secrets \
-d mcr.microsoft.com/mssql/server:2019-latest

I added -u 0:0 to have it run as root user as per https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#nonrootuser

Also added --name sql7 so get a decent name vs something like festive_snyder

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
003d38f30700 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 2 hours ago Up About an hour 0.0.0.0:1407->1433/tcp sql7
4a8d5609096b mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 3 hours ago Exited (1) 3 hours ago festive_snyder

All 3 comments

I have the same issue with the https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#persist section

Two things give the container a name, and change the scropt so it works:

Example of failed code

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Th1sIsStr0ng' \
-p 1408:1433 --name sql8 \
-v /db/data:/var/opt/mssql/data \
-v /db/log:/var/opt/mssql/log \
-v /db/secrets:/var/opt/mssql/secrets \
-d mcr.microsoft.com/mssql/server:2019-latest

Get

darwin@spokeDockerVM:/$ docker logs sql8
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
2020-03-09 22:15:24.28 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-03-09 22:15:24.41 Server ERROR: Setup FAILED copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf': 2(The system cannot find the file specified.)
ERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x80070002)
darwin@spokeDockerVM:/$

Here is how I fixed it:

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=fakePassw0rd' \
-u 0:0 -p 1407:1433 --name sql7 \
-v /home/darwin/database/data:/var/opt/mssql/data \
-v /home/darwin/database/log:/var/opt/mssql/log \
-v /home/darwin/database/secrets:/var/opt/mssql/secrets \
-d mcr.microsoft.com/mssql/server:2019-latest

I added -u 0:0 to have it run as root user as per https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#nonrootuser

Also added --name sql7 so get a decent name vs something like festive_snyder

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
003d38f30700 mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 2 hours ago Up About an hour 0.0.0.0:1407->1433/tcp sql7
4a8d5609096b mcr.microsoft.com/mssql/server:2019-latest "/opt/mssql/bin/perm…" 3 hours ago Exited (1) 3 hours ago festive_snyder

I assume the root of the issue is that you are trying to store data on non-NTFS partition. I had the same issue, I tried to use my Ubuntu partition, but it worked when I used NTFS partition.

Have a look at requirements of the SQL Server on Linux - https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup?view=sql-server-linux-ver15#system

File System: XFS or EXT4 (other file systems, such as BTRFS, are unsupported)

It seems that @DataSnowman 's solution fixes my issue. Thank you!

Was this page helpful?
0 / 5 - 0 ratings