Reputation: 404
I am trying to run a SQL Server container on my mac through Docker.
I ran the following command:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=strongpassword" -p 1433:1433 --name sqlservercontainer -d mcr.microsoft.com/mssql/server:2019-latest
But the container is immediately exiting.
The docker logs for the container look like 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.
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. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
Any idea what needs to be done to solve this?
Upvotes: 9
Views: 20101
Reputation: 91
For docker compose, the only solution that worked for me is below. It's working on Docker Desktop and Rancher.
/var/opt/mssql/data
to work with Docker Desktopsqlserver:
image: mcr.microsoft.com/mssql/server:latest
user: root
hostname: mssql
environment:
- MSSQL_SA_PASSWORD=${SQLSERVER_PASSWORD:-PasSW0rD123@@@}
- ACCEPT_EULA=Y
ports:
- 1433:1433
volumes:
- "/sqlserver:/var/opt/mssql"
- /var/opt/mssql/data
profiles: [sqlserver]
References:
Upvotes: 0
Reputation: 21
I solved for my side using docker-compose with the respective volumes:
version: '3.8'
services:
sql-service:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: sql_server
restart: unless-stopped
environment:
- USER=SA
- SA_PASSWORD=r00t.R00T
- ACCEPT_EULA=Y
ports:
- "1433:1433"
volumes:
- './data:/var/opt/mssql/data'
- './log:/var/opt/mssql/log'
- './secrets:/var/opt/mssql/secrets'
Upvotes: 0
Reputation: 21
everyone
As i am running with compose=>Dockerfile and not mounting anything, was strange to me this error when a i read your comments. But what solved to me was set on Dockerfile User 10001: docker-compose.yaml:
bd:
build: pdvbd
user: root
command: "/opt/mssql/bin/sqlservr --accept-eula & | grep -q \"Service Broker manager has started\" "
ports:
- "1431:1431"
- "1433:1433"
- "1434:1434"
Dockerfile:
FROM mcr.microsoft.com/mssql/server:2022-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=abcDEF123#
ENV MSSQL_PID=Developer
ENV MSSQL_TCP_PORT=1433
EXPOSE 1431
EXPOSE 1433
EXPOSE 1434
WORKDIR /src
USER 10001
RUN (/opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" && ./init.sh
What really solved ? On Dockerfile set the line USER 10001 Hope this help somebody. Thanks.
Upvotes: 0
Reputation: 126
I found that this command works for me, here is why:
chown 10001:10001 <mount directory of /var/opt/mssql>
the uid and gid 10001
most likely won't be mapped to anything in yout host, but it will be mapped to mssql
user inside the official container, here is one line of the passwd
file from the image:
mssql:x:10001:10001::/home/mssql:/bin/bash
Upvotes: 6
Reputation: 39
chown 10001:10001 <mount folder>
https://github.com/microsoft/mssql-docker/issues/735
Upvotes: 1
Reputation: 606
In my case, I am running the SQL server 2022 container on WSL2 - Ubuntu 22.04 and I need to fix the root level of the mapped directory to 775 ( or higher 777 )
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=your_sa_pwd" -p 1433:1433 --name gutlo-sql -h gutlo-sql -v /data/mssql22:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2022-latest
$ ls -lad /data/mssql22/
drwxrwxr-x 6 root root 4096 Jun 22 18:23 /data/mssql22/
And the logs - on a clean new directory, seeding the database
$ docker logs gutlo-sql
SQL Server 2022 will run as non-root by default.
This container is running as user mssql.
... ( lines skipped )
2023-06-22 22:23:22.30 spid26s Recovery is complete. This is an informational message only. No user action is required.
Upvotes: 0
Reputation: 1
If you are having this issue with docker on Synology, SSH into your Synology and update the permissions to your mounted folder.
Upvotes: -1
Reputation: 8829
If you use the sudo
command to create a folder outside of your home directory structure for use by Docker then that folder is going to be owned by the root
user, e.g.:
$ sudo mkdir /var/mssql-data
$ ls -la /var/mssql-data
total 0
drwxr-xr-x 2 root wheel 64B 26 May 11:31 ./
drwxr-xr-x 30 root wheel 960B 26 May 11:31 ../
When you try to launch an SQL Server container using a volume mapping with that folder the container will fail to start - because the Docker backend process doesn't have access - and you will see the "system directory could not be created" error message, e.g.:
$ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=StrongPassw0rd" -p 1433:1433 -v /var/mssql-data:/var/opt/mssql --name sqlservercontainer -d mcr.microsoft.com/mssql/server:2019-latest
9d6bf76a91af08329ea07fafb67ae68410d5320d9af9db3b1bcc8387821916da
$ docker logs 9d6bf76a91af08329ea07fafb67ae68410d5320d9af9db3b1bcc8387821916da
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. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
To correct the situation you need to give your own account access to the folder and then a container using that volume mapping will start successfully:
$ sudo chown $USER /var/mssql-data
$ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=StrongPassw0rd" -p 1433:1433 -v /var/mssql-data:/var/opt/mssql --name sqlservercontainer -d mcr.microsoft.com/mssql/server:2019-latest
3b6634f234024e07af253e69f23971ab3303b3cb6b7bc286463e196dae4de82e
Upvotes: 4