Can't run mssql docker image: permissions_check.sh: exec format error - sql-server

I've trying to run a mssql docker container with Linux 20.04 installed in a Raspberry pi, and I got the following error:
mssql | exec /opt/mssql/bin/permissions_check.sh: exec format error
mssql exited with code 1
My docker compose file is the following:
version: "3.7"
services:
sql-server-db:
container_name: mssql
image: mcr.microsoft.com/mssql/server:2022-latest
#image: mcr.microsoft.com/mssql/server:2019-CU18-ubuntu-20.04
ports:
- "1433:1433"
environment:
MSSQL_SA_PASSWORD: ******
ACCEPT_EULA: Y
volumes:
- ./Data/mssql:/var/opt/mssql/data
Also, I've tried to run the container like this:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=******" -p 1433:1433 --name mssql -d mcr.microsoft.com/mssql/server:2019-CU18-ubuntu-20.04
Additionally, I've tried more than one image with no success.
I've tried everything I have in my hands, I'm starting to losing my mind with this right now....
Things I've tried:
I read an article in stackoverflow about defining a volume inside docker-compose.yml file to the mssql image.
I've put and take single and double quotation marks from the docker-compose.yml file.
As I mentioned before, I tried to run docker run (...) command to check another way around.
I expected these to work since I thought I had a spelling mistake or a comma, quatation mark wrong, etc. All with no success.

Related

Install SQL Server on Mac

I am on the following page:
https://www.quackit.com/sql_server/mac/install_sql_server_on_a_mac.cfm
In step 1, it says to use the following Docker command in a terminal:
docker pull microsoft/mssql-server-linux
However, that command is outdated and did not work.
I made my way to the following URL:
https://hub.docker.com/_/microsoft-mssql-server
I used the following command I found there:
docker pull mcr.microsoft.com/mssql/server:2019-latest
Using the command directly above, I could see the terminal pulling and completing the installation.
So now in step 2, it says to use the following Docker command:
docker run -d --name Homer -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=myPassw0rd' -p 1433:1433 microsoft/mssql-server-linux
But then says if I used a different container, I have to replace "microsoft/mssql-server-linux" with my container image.
This is where I'm stuck.
I tried to use the following:
docker run -d --name Homer -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=myPassw0rd' -p 1433:1433 mcr.microsoft.com/mssql
But I get the following error:
Unable to find image 'mcr.microsoft.com/mssql:latest' locally
docker: Error response from daemon: manifest for mcr.microsoft.com/mssql:latest not found: manifest unknown: manifest tagged by "latest" is not found.
What am I doing wrong?
When you pulled the image, you used:
mcr.microsoft.com/mssql/server:2019-latest
When you ran the container, you used something else:
docker run -d ... mcr.microsoft.com/mssql
Why did you shorten this and leave stuff out of it? Docker can't read your mind or perform auto-complete for you. Try:
docker run -d ... mcr.microsoft.com/mssql/server:2019-latest

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

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.
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)
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)
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
Unfortunately, the only way I found to fix this issue involves a few manual steps.
I used the following docker-compose file for this to work
version: '3.9'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
platform: linux
ports:
- 1433:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<testPASSWORDthatISlongENOUGH_1234>
volumes:
- ./mssql/data:/var/opt/mssql/data
- ./backups:/var/backups
(the data directory has to be mounted directly due to another issue with SQL server containers hosted on Windows machines)
Then you need to perform the following manual steps:
Connect to the database using SSMS
Find and select your .bak database backup file
Open a terminal in the container
In the directory that the .mdf and .ldf files are going to be created, touch files with the database name you are going to use
touch /var/opt/mssql/data/DATABASE_NAME.mdf
touch /var/opt/mssql/data/DATABASE_NAME_log.ldf
Toggle the option to replace any existing database with the restore
Restore your database
I tried to follow the instructions in this https://www.sqlservercentral.com/blogs/using-volumes-in-sql-server-2019-non-root-containers article but I could not get it to work.
This problem was also discussed in this github issue (which the bot un-helpfully closed without a proper solution).
I encoutered the same problem as you trying to run a container based on sql server on DigitalOcean. user: root also solved the issue.

Login fails for SA sql server linux docker

I try to use sql server on docker, linux. I start the container like this:
docker run -d -p 1433:1433 -e sa_password="12345qwerASDF" -e ACCEPT_EULA=Y --name sql-server --hostname sql-server microsoft/mssql-server-linux:2017-latest
When I try to connect, all I get is "Login failed for user 'sa'"
Tried with different password, with and without double and single quotes...
Finally I got it to work:
docker run --name sqlserver --hostname sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest
I guess it should be MSSQL_SA_PASSWORD and not SA_PASSWORD
The documentation isn't clear in that part...
Your password 12345qwerASDF doesn't meet complexity requirements. Try adding a non-alphanumeric characters such as exclamation point (!).
To check for errors, run: docker logs ID (where ID is container ID from docker ps).
For docker-compose file
i was facing problem with sa user login failed i fix it by adding
depends_on:
- db
here's my full version of docker-compose file
version: '3.1'
services:
colour-api:
build: .
environment:
DBServer: "ms-sql-server"
ports:
- "8080:80"
depends_on:
- ms-sql-server
ms-sql-server:
image: mcr.microsoft.com/mssql/server
environment:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: "Pa55w0rd2019"
ports:
- "1444:1433"
Follow this link for more details
https://docs.docker.com/compose/aspnet-mssql-compose/
I got the same error. Stop the sql server services running in your local. Then You can login to sql server(linux) via docker(dbeaver)
1-) I got the error
2-) Stop the sql server services running in your local
3-) Then You can login to sql server(linux) via docker(dbeaver)
I hope it was helpful
Try this :
docker run -e "ACCEPT_EULA=Y" -e "sa_password=12345qwerASDF" -p 1433:1433 --name sql-server --hostname sql-server -d microsoft/mssql-server-linux:2017-latest
IMPORTANT NOTE: If you are using PowerShell on Windows to run these
commands use double quotes instead of single quotes.
Source : https://hub.docker.com/r/microsoft/mssql-server-linux/
I solved my problem with this notes
In formal doc used SA_PASSWORD !!!, but MSSQL_SA_PASSWORD is true (Microsoft team, what are doing?!!!!)
As a docker "[Configuration/Requirements for Microsoft SQL Server][1]" said: " A strong system administrator (SA) password: At least 8 characters including uppercase, lowercase letters, base-10 digits and/or non-alphanumeric symbols."
In Linux, use single quote for define password .
Be sure, before you run "docker run .." , the volume of "data" which you mount from host to container must be clean (if you have it!).
Here is a sample of “docker run” for creation Microsoft SQL Server container.
docker run
-e ACCEPT_EULA=Y
-e MSSQL_SA_PASSWORD='Mssql!Passw0rd'
-e MSSQL_DATA_DIR=/var/opt/mssql/data
-e MSSQL_PID='Developer'
-e MSSQL_TCP_PORT=1433
-p 1433:1433
-v /var/opt/mssql/data:/var/opt/mssql/data
-v /var/opt/mssql/log:/var/opt/mssql/log
-v /var/opt/mssql/secrets:/var/opt/mssql/secrets
--name mssql_2017
-d mcr.microsoft.com/mssql/server:2017-latest
for checking an instance of SQL Server ...
docker exec -it mssql_2017 /bin/bash
cd /opt/mssql-tools/bin/
./sqlcmd -S localhost -U SA -P 'Mssql!Passw0rd'
select ##version
go
I hope this hints can help you.
The docker volume used for the mssql service could be corrupted.
In a docker setup using mcr.microsoft.com/mssql/server:2019-latest
I have encountered a similar problem. Although I had no problem
connecting to the server from a container built from the command line the issue persisted for the docker container.
Removing the volume and recreating the container did the trick.
docker run --name SQLServer -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=“Yourpassword” -e MSSQL_PID="Express" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
Same thing happened to me but the problem was I had a windows desktop version of MSSQL and I forgot to stop the service before connecting to the docker version.

Create SQL Server database from a script in docker

Simple question I hope. I cannot find anything anywhere.
How do you create a database in a Microsoft SQL Server Docker container?
Dockerfile:
I am looking at the following Dockerfile:
FROM microsoft/mssql-server-windows-developer:latest
ENV sa_password ab873jouehxaAGR
WORKDIR /
COPY /db-scripts/create-db.sql .
# here be the existing run commnd in the image microsoft/mssql-server-windows-developer:latest
#CMD ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';", ".\\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \\\"$env:attach_dbs\\\" -Verbose" ]
RUN (sqlcmd -S localhost -U SA -P ab873jouehxaAGR -i create-db.sql)
docker-compose.yml:
I have put together the following docker compose file:
version: '3.4'
services:
sql.data:
image: ${DOCKER_REGISTRY}myfirst-mssql:latest
container_name: myfirst-mssql_container
build:
context: .
dockerfile: ./Dockerfile
environment:
SA_PASSWORD: ab873jouehxaAGR
ACCEPT_EULA: Y
Bringing it together
I am running the command docker-compose up against the above. And assuming create-db.sql file will simply create a database which is not relevant here to keep things minimal.
Errors
The error I get above is that the login for SA is invalid when it runs the .sql script:
Step 7/7 : RUN (sqlcmd -S localhost -U SA -P ab873jouehxaAGR -i create-db.sql)
---> Running in 2ac5644d0bd9
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'SA'..
It looks like this runs before the password has been changed to ab873jouehxaAGR which typically looks like the command from mssql-server-windows-developer:latest.json from inspecting the image in vscode - \start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs actually does.
Environment
I am running docker Docker version 18.06.1-ce, build e68fc7a on Windows 10.
Attach or script
I am not specifying attaching a database using the environment variable attach_dbs of which I see in many examples.
I am trying to find a best practice for managing a sql container from a point of view of end to end testing and a lot of articles seem to not cover the data aspect part - ie Development Workflow
I would be interested to hear in comments thoughts on these two approaches in the Docker world.
using following commands can solve your problem
docker-compose up --build -d
version: '3.4'
services:
sql.data:
image: ${DOCKER_REGISTRY}myfirst-mssql:latest
container_name: myfirst-mssql_container
environment:
SA_PASSWORD: ab873jouehxaAGR
ACCEPT_EULA: Y
and after that:
docker exec myfirst-mssql_container sqlcmd
-d master
-S localhost
-U "sa"
-P "ab873jouehxaAGR"
-Q 'select 1'

How can I drop into a bash shell with docker-compose?

Intention:
I am trying to figure out how to use the command docker-compose up --build to build a machine with an Apache/PHP7.1 service acting as a web server and a MSSQL service as the database for the app that is served from the web server.
I need to be able to type in commands to the docker container while I build this development environment (so that I can look at the PHP logs, etc), but since the web server is running, my terminal is occupied with the output from the web server and when I press ctrl+Z, it actually puts the docker process in the background.
The question:
Is there anyway that I can run this docker-compose.yml file and have it drop me into the shell on the guest machine?
Service 1:
webserver:
image: php:7.1-apache
stdin_open: true
tty: true
volumes:
- ./www:/var/www/html
ports:
- 5001:80
Service 2:
mssql:
image: microsoft/mssql-server-linux
stdin_open: true
tty: true
environment:
- ACCEPT_EULA=Y
volumes:
- ./www:/var/www/html
ports:
- 1433:1433
depends_on:
-webserver
You can exec a new process in a running container.
docker-compose exec [options] SERVICE COMMAND [ARGS...]
In your case
docker-compose exec webserver bash
The -i and -t options from docker exec are assumed in docker-compose exec
First of all, same as docker run, docker-compose has an option for running the services/containers in the background.
docker-compose up --detach --build
After that, list the running containers with:
docker-compose ps
And connect to the container like #Matt already answered.

Resources