Docker Keep Exiting (Deploying MS SQL on MAC osx) - sql-server

I'm trying to deploy an MS SQL server on my MAC. There are several alternatives for that.
Here, I'm using docker: I've checked the MS-SQL website, and I executed this code:
docker run -e
'ACCEPT_EULA=Y'
-e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433
-d microsoft/mssql-server-linux
However, The container keeps stopping by itself.
Did I miss something here?
The docker Version I'm using:
Version 1.13.0 (15072)

I had a similar problem. I finally realized the issue was that I was using a dummy password for local dev that didn't adhere to SQL Server's password policy. I used a more complex password and that fixed it up.

I faced this issue recently on Windows. Changing the ' quotes to " fixed the issue.

If you are using MacOS Ventura and/or using a Mac with M1/M2 (Apple Silicon) chip, you will need to enable the Rosetta Emulation to get this to work.
Go to Docker > Settings > Features in development and enable the option 'Use Rosetta for x86/amd64' emulation on Apple Silicon' and restart Docker.
Also, make sure the password obeys the Password Policy set by Microsoft and create a strong password.
Delete the container and re-run the docker run command. An example is below:
docker run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Ithink%Th5r5f0re$Iam' --name sql_server --platform linux/amd64 -p 1433:1433 mcr.microsoft.com/mssql/server:2022-latest
This should get you run the container without the Exited(1) error.
This link explains the details:
https://devblogs.microsoft.com/azure-sql/development-with-sql-in-containers-on-macos/

When running this on Mac you need to bump up your Docker for Mac's RAM. SQL Server needs minimum 4GB RAM, Docker for Mac by default only allocates about 1-2GB for all containers.
To increase Docker for Mac's RAM:
Open Docker for Mac's preferences
Click "Resources"
Move the RAM slider up, in my case I moved it to 6GB (4GB for SQL Server and 2GB for everything else)
You also need to allocate 4GB to the container when starting it up:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' --memory=4096M -p 1433:1433 -d microsoft/mssql-server-linux
To confirm you memory limits were applied run: docker stats. The MEM USAGE / LIMIT column for the SQL Server container should have output similar to: 536.7MiB / 4GiB
The other thing to watch out for on Mac is that you cannot mount volumes this will cause issues.

Related

Can't Connect "SSMS on Windows" With "SQLServer on Linux" Container On Docker

I've pulled latest SQL Server docker image
docker pull mcr.microsoft.com/mssql/server
Then started with port 1400.
(I'm not using default port 1434 because I've a local instance of SQLServer running outside of docker which my SSMS can quickly connect)
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=pa$$word#123" -e "MSSQL_PID=Express" --name "SQLServer" -p 1400:1400 -d mcr.microsoft.com/mssql/server
This is my container info
When I check the logs everything looks normal. But when I try to connect from SSMS, I'm getting the following error.
What could be the reason? I'm also planning to build a .NET Core application to connect to this docker image but now I've concerns regarding if it's some TLS version mismatch.
I found the solution. I need to specify the instance name in SSMS in order to connect to it

Unable to bind mount a Windows folder in a Linux SQL Server docker image

I'm trying to run the docker image mcr.microsoft.com/mssql/server:2019-latest on a windows host.
When running this command line, everything works fine:
docker run --rm -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=My_Password" -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest
When I try to bind mount the /var/opt/mssql/data folder to access it's content from my windows host, I get the following error:
PS C:\Docker> docker run --rm -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=My_Password" -v C:\SQL\data:/var/opt/mssql/data -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest
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.
2020-05-13 20:39:01.91 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-05-13 20:39:01.99 Server ERROR: Setup FAILED copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf': 31(A device attached to the system is not functioning.)
ERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x8007001f)
It looks like this issue: https://support.microsoft.com/en-us/help/4212960/fix-sql-server-2017-won-t-start-with-linux-container-image-on-docker
Which is supposed to be fixed. But I tried with several version of the docker image, including mcr.microsoft.com/mssql/server:2017-CU7-ubuntu, which is supposed to be the version in which that issue was fixed.
It seems to be an issue in the new Docker for Windows version. I did rollback from 2.3.0.2 to 2.2.0.5, and now the bind mount works as expected.
An issue has been raised about it in the mssql-docker github: https://github.com/microsoft/mssql-docker/issues/600

Docker - SQL service wont run when cloned

I'm trying to add a volume to a docker container but when I commit it and run with the new volume none of the sql services run on this copy?? Why would that be.
https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-powershell
I am adding the initial one as above and it works.All fine. Services running. I can connect to it, run SQL but I need to share a drive.
Seems I cant add one directly to an existing instance??
docker commit 5a8f89adeead newimagename
docker run -ti -v "C:/dir1":/dir1 newimagename /bin/bash
I do the above to clone it and add a volume. WORKS. But the sql services just arent running on this new one. Ill accept it either way I just want SQL running and a share in there.
Can anyone help.
Manged it:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Pa55word1" `
-v C:/db:/dir1 `
-p 1433:1433 --name sql3 `
-d mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
Had an issue with having no drive or no services but this has done it.

Mssql login fail ECONNREFUSED 127.0.0.1:1433

while trying to log in using this .. mssql -u sa -p mypassword .i get this error, Error: Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433
I have installed sql server on docker using this https://www.microsoft.com/en-us/sql-server/developer-get-started/java-mac tutorial and started it.
I am using mac os sierra. I have searched all over internet including stackoverflow for this but gotten no answer. The only answer i get is to enable tcp/ip using sql configuration manager, but mac os doesn't have a configuration manager so I can enable the tcp/ip. Kindly assist.
I finally found the solution .. the docker set the memory as 2GB while the MS SQL server requires 3.25GB... All i had to do was go to the Docker preferences and changed the memory to 4GB and it works :). I was using sql server on docker on Mac.
I'm using docker to set up containers and then sql-cli to access SQL server. This is how I resolved that error which I got after providing mssql -u sa -p mypassword.
What I didn't realize at the beginning was a too simple password provided before with setting up a docker container:
docker run -d --name Homer -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=myPassw0rd' -p 1433:1433 microsoft/mssql-server-linux
The Terminal doesn't say this and only after going to docker > Kitematic and checking the logs of the just created container I saw such a security warning. I deleted that container and created a container with a strong password.
Then I got the error after I've started a wrong container (so the connection failed because I was trying to provide the password for a different container). Since then, I prefer to use Kinematic to manage and access my containers. Before I type mssql -u sa -p mypassword in the Terminal and start to work, I just go to docker > Kinematic and Start my container.
In my case the container exited due to an insecure mssql password.
Try reading the container logs.
In my case, I just needed to start the container.
docker start {container_name}
In my case (I was following this tutorial https://database.guide/how-to-install-sql-server-on-a-mac/) the problem was the host address.
I was trying to connect to localhost and I got the ECONNREFUSED message but then I realized that I needed to use the local IP docker assigned to the container (it was something like 192.168.xxx.xxx), so:
mssql -s 192.168..... -o 1433 -u sa -p 'mypassword'
finally worded.
I had the same, in my case I notice that the problem was the PORT, so:
1)Check if the container is running with
docker start "container_name"
2)Then, get the correct PORT with:
docker ps
3) Run it
mssql -s "PORT" -o 1433 -u sa -p "pwd"
I'm adding this answer to complement Krzysztof Tomasz's answer.
I was following this guide: How to Install SQL Server on a Mac
Everything was going well but at the time of connecting to the container with this command:
mssql -u sa -p mypass1
I got:
Error: Failed to connect to localhost:1433 - connect ECONNREFUSED
127.0.0.1:1433
Then I opened Docker app, clicked the container and in the Logs menu I could see the following:
2020-02-05 16:26:45.71 spid20s ERROR: Unable to set system
administrator password: Password validation failed. The password does
not meet SQL Server password policy requirements because it is too
short. The password must be at least 8 characters..
The password I set had only 7 chars. :o)
Now this makes sense.
This is also documented # Microsoft doc here:
Quickstart: Run SQL Server container images with Docker
Solved this problem by removing the container and launching it again...
As I only had one container I ran the following command:
docker rm $(docker ps -a -q)
Then launched sql server image again with a stronger password:
docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=MyPass11' -p 1433:1433 microsoft/mssql-server-linux
I resolved this issue by updating the port from 1422 to 1433, I used Kitematic to implement this update.
I had the same, and it was a RAM issue, HOWEVER... 4GB didn't do it for me, for some reason in my case I needed 6, then it worked.
Make sure you have started the container in docker.
Command to start a container: docker start container "containerName"
and then try to connect mssql
I had same problem too, after study the logs with two commands:
docker ps -a
then
docker logs 99373f58f2ff
I understood that problem is related to the password dose not to meet SQL Server password policy! That's is.

How to import .bacpac into docker Sqlserver?

I installed Sqlserver on my Mac in a docker container, following the instructions from this article.
I run the container with Kitematic and managed to connect to the server using Navicat Essentials for SQl Server.
The server has four databases and I can create new ones, but, ideally, I would like to import an existing database as .bacpac.
The instructions from this answer have been of use to me in the past. Can I run something similar within the container? Or, more generally, is there a way to import a database in the container?
Hi all! We finally have a preview ready for sqlpackage that is built on dotnet core and is cross-platform! Below are the links to download from. They are evergreen links, i.e. each day a new build is uploaded. This way any checked in bug fix is available the next day. Included in the .zip file is the preview EULA.
linux
https://go.microsoft.com/fwlink/?linkid=873926
osx
https://go.microsoft.com/fwlink/?linkid=873927
windows
https://go.microsoft.com/fwlink/?linkid=873928
Release notes:
The /p:CommandTimeout parameter is hardcoded to 120
Build and deployment contributors are not supported
a. Need to move to .NET Core 2.1 where System.ComponentModel.Composition.dll is supported
b. Need to handle case-sensitive paths
SQL CLR UDT types are not supported.
a. This includes SQL Server Types SqlGeography, SqlGeometry, & SqlHierarchyId
Older .dacpac and .bacpac files that use Json serialization are not supported
Referenced .dacpacs (e.g. master.dacpac) may not resolve due to issues with case-sensitive file systems
For lack of a better method, please provide any feedback you have here on this GitHub issue.
Thanks for giving it a try and letting us know how it goes!
https://github.com/Microsoft/mssql-docker/issues/135#issuecomment-389245587
EDIT: I've made you a Docker image for this
https://hub.docker.com/r/samuelmarks/mssql-server-fts-sqlpackage-linux/
Example of setting up a container, creating a database, copying a .bacpac file over, and importing it into aforementioned database:
docker run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 --name sqlfts0 samuelmarks/mssql-server-fts-sqlpackage-linux
docker exec -it sqlfts0 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourStrong!Passw0rd>' -Q 'CREATE DATABASE MyDb0'
docker cp ~/Downloads/foo.bacpac sqlfts0:/opt/downloads/foo.bacpac
docker exec -it sqlfts0 dotnet /opt/sqlpackage/sqlpackage.dll /tsn:localhost /tu:SA /tp:'<YourStrong!Passw0rd>' /A:Import /tdn:MyDb0 /sf:foo.bacpac
It looks like Microsoft has implemented support of this on sqlpackage, with documentation!
You will have to add sqlpackage to your container.
You can download it here. (optionally, direct link to linux package here, hopefully doesn't change)
The following are instructions for running this from a windows machine -- obviously it's the bare minimum to get it working. Please change passwords, and probably put this in a docker-compose.yml for re-use.
I unzip the above package into a folder 'c:\sqlpackage' (my windows docker run doesn't allow relative paths), and then mount that into the container with the bacpac, like such:
docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Asdf1234" -v c:\sqlpackage:/opt/sqlpackage -v c:\yourdb.bacpac:/tmp/yourdb.bacpac -p 1433:1433 --name mssql-server-example microsoft/mssql-server-linux:2017-latest
here is what a *nix user could run alternatively:
docker run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Asdf1234' -v ./sqlpackage:/opt/sqlpackage -v ./yourdb.bacpac:/tmp/yourdb.bacpac -p 1433:1433 --name mssql-server-example microsoft/mssql-server-linux:2017-latest
and finally, attach to your container and run:
/opt/sqlpackage/sqlpackage /a:Import /tsn:. /tdn:targetdbname /tu:sa /tp:Asdf1234 /sf:/tmp/yourdb.bacpac
After this, you should be able to connect with SSMS to localhost, username and password as you provide them above, and see 'targetdbname'! These are mostly notes I wrote for myself but I'm sure others could use them too.
You can use free Azure Data Studio from Microsoft. Once you have it installed, install the extension "Admin Pack for SQL Server" from Microsoft. Then you can import bacpac files with ease.
This is not a supported feature with a LINUX implementation it seems.
See this link.

Resources