Following previous post, where I discussed how to use Docker and PostgreSQL for local development, recently I needed to use Microsoft SQL Server for local development. Here are the commands to use Docker and MSSQL for local development.
Run docker container for MSSQL 2019 (latest typical includes most of updates):
$ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Pa$$w0rd2019" \
-e "MSSQL_PID=Express" \
-p 1433:1433 --name tatemo_mssql_01 -h tatemo_mssql_01 \
-d mcr.microsoft.com/mssql/server:2019-latest
Brief description of parameters:
-e “ACCEPT_EULA=Y” <— Required. You must accept this.
-e “SA_PASSWORD=Pa$$w0rd2019″ <— Required. At least 8 characters of at least three of these four categories: uppercase letters, lowercase letters, numbers and non-alphanumeric symbols.
-e “MSSQL_PID=Express” <— Indicates type of product to use in container, defaults to Developer (the developer edition). See below for more options.
-p 1433:1433 <— Ports to use in host, mapped to internal use.
–name tatemo_mssql_01 <— Desired name for container, if not provided then a random name is assigned.
-h tatemo_mssql_01 <— Set container hostname, if you don’t set it, then defaults to a random generated system GUID.
-d <— Indicates to run container in deattach mode.
mcr.microsoft.com/mssql/server:2019-latest <— Required. The SQL Server 2019 Ubuntu Linux container image.
Once container is running, use following command to connect to container:
$ docker exec -it tatemo_mssql_01 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password>
Last command is not complicated to understand: it executes a command “/opt/mssql-tools/bin/sqlcmd
” against container “tatemo_mssql_01
” using some parameters “-S localhost -U sa -P <your_password>
” to connect identify to server. Parameters “-it
” makes an interactive shell.
I hopes this helps when you need to use Docker and MSSQL for local development.