Docker - SQL service wont run when cloned - sql-server

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.

Related

Mongodb running on Docker is wiping the collection after restart

I have to build a small application that reads data from MongoDB running on docker and uses it for further processes.
The problem is that after I close docker, the local instance of the database is also getting deleted. How can I stop it?
The MONGODB_URI is mongodb://localhost:27017 and what are the attributes that I should add in the docker command to avoid it. should I avoid using localhost? docker-compose seems confusing to me so I use Dockerfile.
So, what exactly can be the docker run command to avoid it? is it one of these?
Commands: docker run -d --name mongo-on-docker -p 27017:27017 mongo
docker run -d --name sample --link mongo-on-docker web app
Also to permanently save what data directory should I use?
Docker container are dead before quiting. For store data you should mount named volume, folder or file to the container.
In MongoDB case try:
docker run --rm -ti -v mongo_data:/data/db mongo bash
Where mongo_data is a special Docker entity, that can be mounted as a folder into container. Including in different containers at the same time.
Not new:
How to set docker mongo data volume

Connect to created database with created user in a docker container

i’m trying to connect to a postgre database which is inside a docker container. I´m creating the docker container with following command:
docker run --name prodcoc -p 5432:5432 -e POSTGRES_USER=testuser -e POSTGRES_PASSWORD=test -e POSTGRES_DB=testDB postgres
After the container is running I want to connect to the created database with the created user, but that seems not possible. Why can't I connect to the database which I'm creating with the enviroment variables?
The solution for my problem was to uninstall the local PostgreSql instance. I don´t know why I installed it but removing it solved my problem.
In windows this can be done in the Settings.

Can Docker Containers maintain state between restarts?

Should containers be able to maintain state?
I am using a SQLServer Image like so.
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest
Then I create a database in it using dotnet ef.
dotnet ef database update -v
Database works fine until I restart the container. At which point my database is gona and the container is reset to it's initial state.
What am I missing? Do containers not persist state?
If so what's the point in using them for databases?
Yes they can if you don not delete the container so you can
docker stop xxx
or just simply restart your machine and than use
docker start xxx
or
docker restart xxx
if you use docker run you create a new container so there is no previous state to talk about. For sql server specifically there is an option to create a volume and store data there. If you do that you can delete a container and recreate it again without loosing data as its is no longer stored inside it.

Docker Keep Exiting (Deploying MS SQL on MAC osx)

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.

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