I'm trying to run SQL-Server 2019 in docker in Ubuntu 18.04.
This is how I want it to look:
mkdir -p /var/opt/mssql_2019
docker run -d -p 2019:1433 --name mssql_2019 -e 'MSSQL_SA_PASSWORD=TopSecret123456!abc' -e 'ACCEPT_EULA=Y' -e MSSQL_PID="Developer" -v /var/opt/mssql_2019:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2019-latest
I issue the command, and sql-server exits immediately, not even an entry in the logfile in /var/opt/mssql_2019, hell, not even a file created there.
If I omit
-v /var/opt/mssql_2019:/var/opt/mssql
then it works fine.
Doing exactly the same with sql-server 2017 worked fine.
I run docker logs <containterID> and I get
SQL-Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more, visit...
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. Error [13].
I set permisson on /var/opt/mssql_2019 for group mssql to read&write...
Am I doing something wrong here, or is this a bug ?
If this is a permission issue, how can I get the container to run as root ?
If I switch to su mssql, I can create and delete files and folders in /var/opt/mssql_2019 without problems.
Also, if I add user mssql to sudo
adduser mssql sudo
that doesn't help.
It should be noted that the docker file says
RUN useradd -M -s /bin/bash -u 10001 -g 0 mssql
RUN mkdir -p -m 770 /var/opt/mssql && chgrp -R 0 /var/opt/mssql
but on my computer, user mssql already exists as user 999...
Probably added by sql-server 2017...
Solved, don't know which one of the following did the trick
Rename the existing mssql user to mssql_2017
Add user mssql, add to group 0
Add permissions to /var/opt/mssql_2019 and /var/opt/mssql.
Maybe it would have sufficed to just chgrp -R 0 /var/opt/mssql_2019
usermod --login mssql_2017 mssql
useradd -M -s /bin/bash -u 10001 -g 0 mssql
chgrp -R 0 /var/opt/mssql
chgrp -R 0 /var/opt/mssql_2019
from dockerfile excerpt in
https://blog.dbi-services.com/using-non-root-sql-server-containers-on-docker-and-k8s/
Maybe it either should check if the user already exists, or it should create a separate user for every mssql-version. Don't know if the docker stuff uses the id or the username for permisson.
mkdir mssql && cd mssql
mkdir data
chown 10001 data
Run container
Had to do this three times now because of permissions.
I have this issue in k8s. :((
# k logs mssql-57f6f78dbb-4jwwk
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.
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. Errno [13]
Problem has been resolve with running this command in the host:
chown 10001:0 [the-path-of-the-mounted-volume]
I had the same problem, I solved it in the following way.
my docker compose was has follows
sqlserver:
container_name: "sqlserver"
hostname: "sqlserver"
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "<my_password_here>"
ACCEPT_EULA: "Y"
ports:
- 2533:1433
volumes:
- /var/lib/docker/volumes/mssql_db/_data:/var/opt/mssql
expose:
- 2533
and the change that applies was the following
- /var/lib/docker/volumes/mssql_db/_data:/var/opt/data
finally this worked
There are few solution for this problem:
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
sudo docker run -it mcr.microsoft.com/mssql/server id mssqluid=10001(mssql) gid=0(root) groups=0(root)sudo chown 10001 VOLUME_DIRECTORYSource in spanish: https://www.eiximenis.dev/posts/2020-06-26-sql-server-docker-no-se-ejecuta-en-root/
Give full access to db files on host
sudo chmod 777 -R VOLUME_DIRECTORY
I have this issue in k8s. :((
# k logs mssql-57f6f78dbb-4jwwk 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. /opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. Errno [13]
And, when I change the mapping to /var/opt/mssql/data I get this :
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.
2021-01-15 23:50:05.95 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2021-01-15 23:50:06.05 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)
Why is an Ubuntu image looking in C: drive for template data?
Most helpful comment
Problem has been resolve with running this command in the host:
chown 10001:0 [the-path-of-the-mounted-volume]