Skip to content

Daily: Running Microsoft SQL-Server in Docker

  •  

Introduction

Using Docker is an effortless way to launch and run an application/server software without annoying installation hassles: Just run the image and you’re done.

Even if it’s quite an uncomplicated way of looking at it, in many cases it works just like that.

So, let’s start with using Microsoft SQL Server as a database backend. We will use a docker image from Microsoft. Look here to find out more.

docker	run                                       \
			--name mssql-server       \
			--memory 4294967296       \	
			-e "ACCEPT_EULA=Y"        \
			-e "SA_PASSWORD=secret"   \
			-p 1433:1433              \
			mcr.microsoft.com/mssql/server:2019-latestles

FAQ

Error: program requires a machine with at least 2000 megabytes of memory

Start the docker container as described on the Docker Hub Page: How to use this Image

❯ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=secret" -p 1433:1433 mcr.microsoft.com/mssql/server:2022-latest

Depending on how your docker environment is configured, this could bring up an error:

SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
sqlservr: This program requires a machine with at least 2000 megabytes of memory.
/opt/mssql/bin/sqlservr: This program requires a machine with at least 2000 megabytes of memory.

As the error message states, the MS SQL server needs at least 2g of RAM. So, you must assign your Docker VMs more memory. This is configured in the Docker Dashboard.

Hint: Docker has two ways of running containers:

  • using Windows Container
  • using WSL (Windows Subsystem for Linux)

You can change the way with the context menu of the docker symbol in the task bar:

With Linux Containers (using WSL as backend), you must configure the containers via a file .wslconfig.

This file is in the folder defined by the environment variable %USERPROFILE%, which is normally C:\Users\<username>

To open the file, run the command:

From Command Promptnotepad %USERPROFILE%.wslconfig
From PowerShellnotepad $ENV:USERPROFILE.wslconfig

Edit the content and change the memory setting

[wsl2]
memory=3GB

Restart WSL with the new settings.

❯ wsl --shutdown

Start Container again, now everything should work

❯ docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=secret" -p 1433:1433 mcr.microsoft.com/mssql/server:2022-latest

Leave a Reply

Your email address will not be published.