SQL Server in a Fedora Docker Container

Docker - SeniorDBA

Running SQL Server on Linux is a new and exciting idea only recently made possible by Microsoft. With the technology giant embracing Linux in this new way, the prospect of running SQL Server in a container on Fedora is something you may need a little help doing the first time.

In this article by Langdon White, we get some step-by-step instructions on making the process easy to follow:


First you need to get docker installed. In short, run these commands:

sudo dnf install docker
sudo systemctl start docker

By default, you’ll need to run docker as root or with sudo, but you can change that if desired. Check out the Fedora Developer page on docker for more details and more elaborate setups.

Setting up SQL Server

To pull the Docker image with SQL Server, run this command:

docker pull langdon/fedora-mssqlserver

You will see it download all the layers. The process goes faster if you’ve pulled a Fedora docker image in the past. To run it, use this command (copy and paste makes this easier):

docker run -d -t -p 1433:1433 -v $DATADIR:/var/opt/mssql/data:rw,z -v $LOGDIR:/var/opt/mssql/log:rw,z -e ACCEPT_EULA=$ACCEPT_EULA -e SA_PASSWORD=$SA_PASSWORD langdon/fedora-mssqlserver

To explain this long command a bit:

  • -p 1433:1433 — This is the port exposed from the container to connect to SQL Server. This command binds 1433 on your machine to the container port. You can also use an arbitrary port by just using -P if you’re using 1433 for something else.
  • $DATADIR — Either replace this with a local directory, or set an environment variable for where SQL Server should store its data.
  • $LOGDIR — Just like $DATADIR except for logs.
  • $ACCEPT_EULA — You need to accept the Microsoft license agreement to use this software.
  • $SA_PASSWORD — The default admin user in SQL Server is SA and this is where you set its password. Probably better to replace this than set an environment variable.

Check to ensure your container is running:

docker ps

There should be an entry similar to this:

381a922c2a3e langdon/fedora-mssqlserver "/start.sh" 3 seconds ago Up 2 seconds>1433/tcp angry_jepsen
Connecting to SQL Server

Finally, you can connect to the container. To get the tools, run these commands:

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
dnf install -y --allowerasing mssql-tools

Note that –allowerasing may be needed depending on your package set. The mssql-tools package requires a different version of unixODBC than is shipped in Fedora.

Now you have a sqlcmd utility you can use to connect like this:

sqlcmd -U sa -P $SA_PASSWORD

For $SA_PASSWORD use the password you provided when you started the container running. Finally, to prove SQL Server is up and working, use these commands:

1> SELECT Name from sys.Databases;
2> GO

You can read the entire article here.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.