How to get started with Microsoft SQL Server on Linux using Docker

Posted on March 3, 2019 by Michael Roma

Below is a command to start a container with port and volume mapping. Replace /Users/username/docker/mssql-data with the local path to use for the volume data

docker run \
     --name mssql-test \
     -d \
     -e 'ACCEPT_EULA=Y' \
     -e 'SA_PASSWORD=StrongP@ssword!' \
     -e 'MSSQL_PID=Express' \
     -p 1433:1433 \
     -v /Users/username/docker/mssql-data:/var/opt/mssql \
     microsoft/mssql-server-linux


Once you have the container running, I recommend using Azure Data Studio to connect and manage the server. Download it here: https://docs.microsoft.com/en-us/sql/azure-data-studio/download?view=sql-server-2017.


To create a database in the default directory:

CREATE DATABASE MyAppDB;


To create a login for the server:

CREATE LOGIN app_user WITH PASSWORD = 'TheStrongP@ssw0rd!';


To create a user in the database for an existing login:

CREATE USER [app_user] FOR LOGIN [app_user];


To give db_owner access to the user:

EXEC sp_addrolemember N'db_owner', N'app_user'


To create a schema:

CREATE SCHEMA App;
comments powered by Disqus