Skip to content

Latest commit

 

History

History

mssql-server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

yakworks/mssql-server

based on https://github.com/shanegenschaw/mssql-server-linux

This image is an extension of the official microsoft/mssql-server-linux Docker image

It adds functionality to initialize a fresh instance. Similiar to what MySql has available, when a container is started for the first time, it will execute any files with extensions .sh or .sql or restore and .bak that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your SQL Server services by mounting scripts into that directory and provide custom images with contributed data.

Will also first gunzip sql files if they end with .sql.gz

Restoring Backups with .bak files

Restoring bak files is fast, much faster than running sql to initialize a database. If a file has a .bak extension in docker-entrypoint-initdb.d then it will restore a database as the filename without the .bak , so when backing up a database it should be similiar to the setting below.

For example to restore foo_db databse and run sql script on it

  1. create directory docker-entrypoint-initdb.d
  2. put foo_db.bak file into docker-entrypoint-initdb.d directory
  3. put sqlTest.sql file with some sql statements into docker-entrypoint-initdb.d directory
  4. run this image as [below](## Running this image)

Running image will start sql-server docker and then restore foo_db db from foo_db.bak as the following

sqlcmd -U sa -P $SA_PASSWORD -Q \
    "RESTORE DATABASE foo_db FROM DISK = '/docker-entrypoint-initdb.d/foo_db.bak' 
    WITH MOVE 'foo_db' TO '/var/opt/mssql/data/foo_db.mdf', 
    MOVE 'foo_db_log' TO '/var/opt/mssql/data/foo_db_log.ldf'"

After restore it will run sqlTest.sql (or more sql statements in alphabetical order).

Running this image

docker run -p 1433:1433 --name mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Strong(!)Password' -v $PWD/initdb.d:/docker-entrypoint-initdb.d -d yakworks/mssql-server:2017

Dockerfile based on this image

FROM yakworks/mssql-server:2017

COPY baks/* /docker-entrypoint-initdb.d/

Additional information:

  • Linux-based mssql-docker git repo
  • Running SQL Server on Linux on top of an Ubuntu 16.04 base image.
  • Note that the version 2017-CU3 currently (as of Feb. 15, 2018) has a bug described here: microsoft/mssql-docker#136
  • Make sure that the .sh files have UNIX-style (LF) line endings. Depending on your platform and Git configuration, Git may change them to Windows-style (CR+LF). In this case, the container won't start, and you may see a non-informative error message like:
standard_init_linux.go:195: exec user process caused "no such file or directory"'.