Mssql-docker: Mount a host directory as data volume - error. Docker toolbox on Windows 7

Created on 1 Jun 2017  路  4Comments  路  Source: microsoft/mssql-docker

Using docker toolbox on Windows 7 Professional x64:

$ docker version
Client:
 Version:      17.05.0-ce
 API version:  1.29
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Fri May  5 15:36:11 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.05.0-ce
 API version:  1.29 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 21:43:09 2017
 OS/Arch:      linux/amd64
 Experimental: false

As described here https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-docker#a-idpersista-persist-your-data I'd like to mount a host directory as data volume:

$ docker run --name sqlserver -v /c/shared/sqlserver:/var/opt/mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=StrongPassword1!' -p 1433:1433 -d microsoft/mssql-server-linux

results:

$ docker logs sqlserver -f
This is an evaluation version.  There are [162] days left in the evaluation period.
2017-06-01 18:11:19.78 Server      Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2017-06-01 18:11:19.86 Server      Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2017-06-01 18:11:19.87 Server      Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'.
2017-06-01 18:11:19.88 Server      Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2017-06-01 18:11:19.90 Server      Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2017-06-01 18:11:19.93 Server      Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'.
2017-06-01 18:11:20.04 Server      Microsoft SQL Server 2017 (CTP2.1) - 14.0.600.250 (X64)
        May 10 2017 12:21:23
        Copyright (C) 2017 Microsoft Corporation. All rights reserved.
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS)
2017-06-01 18:11:20.04 Server      UTC adjustment: 0:00
2017-06-01 18:11:20.05 Server      (c) Microsoft Corporation.
2017-06-01 18:11:20.05 Server      All rights reserved.
2017-06-01 18:11:20.05 Server      Server process ID is 4116.
2017-06-01 18:11:20.05 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2017-06-01 18:11:20.06 Server      Registry startup parameters:
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog
2017-06-01 18:11:20.07 Server      Error: 17113, Severity: 16, State: 1.
2017-06-01 18:11:20.07 Server      Error 87(The parameter is incorrect.) occurred while opening file '/var/opt/mssql/data/master.mdf' to obtain configuration information at startup. An invalid startup
 option might have caused the error. Verify your startup options, and correct or remove them if necessary.

host directory:

$ ls -la /c/shared
total 12
drwxr-xr-x 1 Maciek 197121 0 cze  1 20:10 ./
drwxr-xr-x 1 Maciek 197121 0 cze  1 20:10 ../
drwxr-xr-x 1 Maciek 197121 0 cze  1 20:10 sqlserver/

Without mounting (-v) container runs successfully.
What's more I am able to mount a different container directory (eg. /mnt) but I'm not able to mount a directory which contains db files (I need to have it sharable with host as I have some script which is being run outside container and need a path to db files).
Has anyone encountered similar issue?

Most helpful comment

I believe i found a solution for this problem.
Simply add the following

 - ./.db:/var/opt/mssql/
 - /var/opt/mssql/data

This is how my docker-compose looks like.

version: '3'

services:
  db:
    image: microsoft/mssql-server-linux:2017-latest
    volumes:
      - ./.db:/var/opt/mssql/
      - /var/opt/mssql/data
    ports:
      - 8010:1433
      - 8011:1434
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=Mysql!Server02

EDIT: This way was the closest i could get. It will not save your database inside the current folder, it will just make it read only. But the rest of the files will be saved in the current folder. According to microsoft docs (https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#persist) it is not possible on Docker for Mac or Linux.

Host volume mapping for Docker on Mac with the SQL Server on Linux image is not supported at this time. Use data volume containers instead. This restriction is specific to the /var/opt/mssql directory. Reading from a mounted directory works fine. For example, you can mount a host directory using 鈥搗 on Mac and restore a backup from a .bak file that resides on the host.

I tried copy files back and forth with docker cp mssql_db_1:/var/opt/mssql/data data and docker cp data mssql_db_1:/var/opt/mssql/ but it did not work either. Seems like the only way is to follow their instructions after all and use their backup documentation

All 4 comments

This is a toolbox problem. Docker Toolbox does not allow to mount shares from any location. Please check toolbox documentation as this has nothing to do with a specific container or mssql images

I believe i found a solution for this problem.
Simply add the following

 - ./.db:/var/opt/mssql/
 - /var/opt/mssql/data

This is how my docker-compose looks like.

version: '3'

services:
  db:
    image: microsoft/mssql-server-linux:2017-latest
    volumes:
      - ./.db:/var/opt/mssql/
      - /var/opt/mssql/data
    ports:
      - 8010:1433
      - 8011:1434
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=Mysql!Server02

EDIT: This way was the closest i could get. It will not save your database inside the current folder, it will just make it read only. But the rest of the files will be saved in the current folder. According to microsoft docs (https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017#persist) it is not possible on Docker for Mac or Linux.

Host volume mapping for Docker on Mac with the SQL Server on Linux image is not supported at this time. Use data volume containers instead. This restriction is specific to the /var/opt/mssql directory. Reading from a mounted directory works fine. For example, you can mount a host directory using 鈥搗 on Mac and restore a backup from a .bak file that resides on the host.

I tried copy files back and forth with docker cp mssql_db_1:/var/opt/mssql/data data and docker cp data mssql_db_1:/var/opt/mssql/ but it did not work either. Seems like the only way is to follow their instructions after all and use their backup documentation

NICE!

It was probably an issue of having an old installation of docker version. I had installed docker 1.0 now I have installed docker 1.10 and everything works fine!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

superbobdthm picture superbobdthm  路  7Comments

andyjansson picture andyjansson  路  3Comments

Ducatel picture Ducatel  路  4Comments

jwelchpw picture jwelchpw  路  4Comments

schrc3b6 picture schrc3b6  路  5Comments