Skip to content

mssql container project for developers with database provisioning

License

Notifications You must be signed in to change notification settings

iWitzky/mssql-dev

Repository files navigation

mssql-dev - Docker project for MS SQL Server Container with batteries for lazy developers

  • 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.

Provisioning of the SQL server:

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:

  1. 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!
  2. 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!
  3. MS SQL Server Database Backup as gzip archive (.bak.gz)
  4. SQL files (.sql)
  5. SQL files as gzip archive (.sql.gz)
  6. shell script (.sh)

docker-compose.yml - example - individual file mount:

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_.

docker-compose.yml - example - directory mount:

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:

  1. 01_createDB.sql
  2. devDB.bak
  3. my_script.sh
  4. zz_cleanup.sql

docker commands:

  • 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>'

docker-compose commands:

  • 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>'

About

mssql container project for developers with database provisioning

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published