How to import .bacpac into docker Sqlserver?

I installed Sqlserver on my Mac in the dock container following the instructions in this article .

I started the container with Kitematic and was able to connect to the server using Navicat Essentials for SQl Server. There are four databases on the server, and I can create new ones, but ideally I would like to import an existing database like .bacpac.

The instructions from this answer have been helpful to me in the past. Can I run something like this in a container? Or, in a more general sense, is there a way to import a database into a container?

+12
source share
3 answers

Hello everyone! Finally, we have a ready-made preview for sqlpackage, which is built on the dotnet core and is cross-platform! Below are the links to download from. These are evergreen links, that is, a new assembly is laid out every day. Thus, any corrected fix is ​​available the next day. A preliminary license agreement is included in the .zip file. 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 option is hard-coded for 120 Build, and deployment participants are not supported a. You must upgrade to .NET Core 2.1, which supports System.ComponentModel.Composition.dll b. The need to handle case-sensitive paths. SQL CLR UDT types are not supported. a. This includes the SQL Server types SqlGeography, SqlGeometry, and & SqlHierarchyId. Older .dacpac and .bacpac files using Json serialization are not supported. References

In the absence of a better method, please leave your feedback on this issue on GitHub.

Thank you for trying and telling us how this happens!

https://github.com/Microsoft/mssql-docker/issues/135#issuecomment-389245587

EDIT: I made you a Docker image for this

https://hub.docker.com/r/samuelmarks/mssql-server-fts-sqlpackage-linux/

An example of setting up a container, creating a database, copying a .bacpac file and importing it into the aforementioned database:

docker run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 --name sqlfts0 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 
+5
source

It looks like Microsoft has implemented support for this in sqlpackage, with the documentation !

You will need to add sqlpackage to your container.

You can download it here. (optional, a direct link to the linux package here , hopefully, will not change)

Below are instructions for starting this from a Windows machine - obviously this is the minimum to get it working. Please change the passwords and probably put them in docker-compose.yml for reuse.

I unpack the above package into the "c: \ sqlpackage" folder (my launch of Windows Docker does not allow relative paths) and then mount it in a container with bacpac , for example:

docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Asdf1234" -vc:\sqlpackage:/opt/sqlpackage -vc:\yourdb.bacpac:/tmp/yourdb.bacpac -p 1433:1433 --name mssql-server-example microsoft/mssql-server-linux:2017-latest

here is what * nix user can * alternatively run:

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 it to the container and run:

/opt/sqlpackage/sqlpackage /a:Import /tsn:. /tdn:targetdbname /tu:sa /tp:Asdf1234 /sf:/tmp/yourdb.bacpac

After that, you can connect to SSMS with localhost, username and password, as you indicated above, and see "targettdbname"! These are mainly notes that I wrote for myself, but I'm sure others can use them too.

+1
source

This is not supported with the LINUX implementation, it seems.

See this link .

0
source

Source: https://habr.com/ru/post/1012465/


All Articles