- Enhanced entrypoint.sh for individual file provisioning without image rebuild.
- The Dockerfile is based on the official "Microsoft SQL Server on Linux" image: https://hub.docker.com/_/microsoft-mssql-server
- Using the mcr.microsoft.com/mssql/server:2017-CU24-ubuntu-16.04 image.
Mount your files to the container directory /initdb.d to initialize the sql server with your data.
The directory /initdb.d can be included as a whole or each provisioning file individually.
Supported file formats:
- MS SQL Server Database Backup (.bak)
Note:- The name of the database to restore is determined from the file name of the mounted backup without the file extension .bak!
- Restoring a database with a changed database name is not supported!
- Existing databases will not be restored!
- Keep track of naming conventions for MS SQL Server databases!
- MS SQL Server Database Backup as a single file in a 7zip archive (.bak.7z)
Note:- Only one database backup may be packed in a 7zip archive!
- The 7zip archive must be named like the file of the database backup with the extension .7z
- The file of the database backup must be located directly in the 7zip archive without subdirectories!
- The instructions for point 1 still apply!
- MS SQL Server Database Backup as gzip archive (.bak.gz)
- SQL files (.sql)
- SQL files as gzip archive (.sql.gz)
- shell script (.sh)
services:
mssql:
image: mssql-dev:2017-CU24-ubuntu-16.04
volumes:
- ./DevDatabase_1.1.bak.gz:/initdb.d/DevDatabase.bak.gz
- ./cleanup.sql:/initdb.d/zz_cleanup.sql
In this example, the backup is restored as DevDatabase. The name of the database is determined from the filename of the mounted backup without the file extension .bak! The SQL script should be processed at the end of the provisioning, so the filename is preceded by z_.
services:
mssql:
image: mssql-dev:2017-CU24-ubuntu-16.04
volumes:
- ./:/initdb.d/
This example would try to restore a backup DevDatabase_1.1.bak.gz as database DevDatabase_1.1
The processing order of the files in the /initdb.d directory corresponds to the default sorting of the ls command. Example:
- 01_createDB.sql
- devDB.bak
- my_script.sh
- zz_cleanup.sql
- Build
docker build -t mssql-dev:2017-CU24-ubuntu-16.04 .
- Start
docker run -d --name mssql-dev -v $(pwd)/DevDatabase_1.1.bak.gz:/initdb.d/DevDatabase.bak.gz -p 1433:1433 mssql-dev:2017-CU24-ubuntu-16.04
- SQLcmd:
docker exec -it mssql-dev /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P '<your_password>'
-
Build
docker-compose build mssql
-
Start
docker-compose up -d mssql
-
SQLcmd:
docker-compose exec mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P '<your_password>'