Code Monkey home page Code Monkey logo

mssql-initialized's Introduction

Reference

This image is based on the official documentation from Microsoft: https://github.com/microsoft/mssql-docker/tree/master/linux/preview/examples/mssql-customize

It has been adapted to support Sql Server 2022 and provide an initialization framework for a first database and an associated user.

The goal of this image is to simplify the usage of Sql Server docker images in development environment.

How to use this image

Start a Sql Server instance

Starting a Sql Server instance is simple:

$ docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" -p 1433:1433 -d mssql-initialized:latest

... where mssql is the name you want to assign to your container, <YourStrong!Passw0rd> is the password to be set for the System Administrator (SA) user and latest is the tag specifying the version you want. See the list above for relevant tags.

Start an initialized Sql Server instance

The additional parameters (MSSQL_DATABASE, MSSQL_USER and MSSQL_PASSWORD) allow for the preparation of a database right after the start of the server:

$ docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" -e "MSSQL_DATABASE=HelloWorld" -e "MSSQL_USER=hello" -e "MSSQL_PASSWORD=World!Passw0rd" -p 1433:1433 -d mssql-initialized:latest

Environment variables

Official

Source and full list: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables

ACCEPT_EULA

Required.

Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. Required setting for the SQL Server image.

MSSQL_SA_PASSWORD

Required.

Configure the SA user password.

Additional

Here are the environment variables that have been added to the Sql Server docker image to offer pre-initialization features.

MSSQL_DATABASE

Optional.

Define the name of the database to be created after the initialization of the server.

MSSQL_USER

Required if MSSQL_PASSWORD is defined. Ignored if MSSQL_DATABASE is not defined.

Define the username of the account created during initialization. This account will have the db_owner right on the initial database.

MSSQL_PASSWORD

Required if MSSQL_USER is defined. Ignored if MSSQL_DATABASE is not defined.

Define the password of the account created during initialization.

Custom scripts

The initialization process supports two custom scripts that can be provided using volumes. They are both stored in the /usr/config/ folder.

init.sql

This script will be executed if MSSQL_DATABASE, MSSQL_USER and MSSQL_PASSWORD are defined. It will be executed on the created database with the dedicated user and can be used to configure the database itself.

$ docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" -e "MSSQL_DATABASE=HelloWorld" -e "MSSQL_USER=hello" -e "MSSQL_PASSWORD=World!Passw0rd" -v local-init.sql:/usr/config/init.sql:ro -p 1433:1433 -d mssql-initialized:latest

init-sa.sql

This script will be executed if MSSQL_DATABASE is defined. It will be executed on the master database with the SA account and can be used to configure the server itself.

$ docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" -e "MSSQL_DATABASE=HelloWorld" -e "MSSQL_USER=hello" -e "MSSQL_PASSWORD=World!Passw0rd" -v local-init-sa.sql:/usr/config/init-sa.sql:ro -p 1433:1433 -d mssql-initialized:latest

Execution order

flowchart TD
    S[start] --> A
    A{MSSQL_DATABASE is defined}
    A -->|false| B[No scripts executed]
    A -->|true| C[Create the database]
    B --> End
    C --> D{MSSQL_USER is defined}
    D -->|true| E[Create the user]
    D -->|false| G
    E --> F[Execute init.sql]
    F --> G[Execute init-sa.sql]
    G --> End[end]
Loading

mssql-initialized's People

Contributors

superfaz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.