Unable to run SQL Server 2019 docker with volumes and get ERROR: Setup FAILED copying system data file

Viewed 6744

When I run latest sql server image from official documentation on linux host.

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=asdasdasdsad' -p 1433:1433 -v ./data:/var/opt/mssql/data -d mcr.microsoft.com/mssql/server:2019-latest

I get error:

ERROR: Setup FAILED copying system data file 'C:\templatedata\model_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf':  5(Access is denied.)

This message occurs only on Linux host and with binded volumes.

2 Answers

I happen because lack of permission. On 2019 mssql docker move from root user images into not-root. It made that docker sql-server containers with binded volumes and run on Linux host has a permission issue (=> has no permission to write into binded volume).

There are few solution for this problem:

1. Run docker as root.

eg. compose:

version: '3.6'
services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2019-latest
    user: root
    ports:
      - 1433:1433
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=BLAH
    volumes:
      - ./data:/var/opt/mssql/data

Source: https://github.com/microsoft/mssql-docker/issues/13#issuecomment-641904197

2. Setup proper directory owner (mssql)

  1. Check id for mssql user on docker image sudo docker run -it mcr.microsoft.com/mssql/server id mssql gives: uid=10001(mssql) gid=0(root) groups=0(root)
  2. Change folder's owner sudo chown 10001 VOLUME_DIRECTORY

Source in Spanish: https://www.eiximenis.dev/posts/2020-06-26-sql-server-docker-no-se-ejecuta-en-root/

3. Give a full access (not recommended)

Give full access to db files on host sudo chmod 777 -R VOLUME_DIRECTORY

I encoutered the same problem as you trying to run a container based on sql server on DigitalOcean. user: root also solved the issue.

Related