Running Redis and SQL Express on Docker for Windows

As a developer, if you need to run Redis or SQL Express on your local Windows machine, you can install those directly on Windows. However, if you are building containerized apps, you may want to run Redis and SQL Express in a Docker container.

This article will detail the steps to install Docker for Windows, SQL Express and Redis.

Overview

Here is an overview of the steps:

  • Install Docker for Windows
  • Enable experimental mode on Docker for Windows
  • Download and start the SQL Express image
  • Download SQL Management Studio and connect to the SQL Express instance to verify it is working
  • Download and start the Redis image
  • Download and run Redis Insights to verify it is working
Install Docker for Windows

Download Docker for Windows here.

Important! When going through the installation options:

  • Check the box to enable Windows containers
  • It may prompt you to install additional Windows features – let’s do it

Once Docker is installed, open a command prompt or PowerShell console and type docker version to ensure Docker is running. It should return the current version.

Enable experimental mode on Docker for Windows

In order to run the Redis image, we need to enable experimental mode in Docker for Windows.

Open Docker settings and click on “Docker Engine”. Set “experimental” to true in the pane.

This will cause Docker to restart.

Next, we will download and start the SQL Express image.

Download and start the SQL Express image

We are going to install SQL Express on Docker. You can read more about this SQL Express image on Docker Hub.

In the Docker command below, we are configuring a few key settings:

  • We are mapping port 1433 on the local machine to 1433 on the SQL Express container in Docker. If you have SQL running on your local machine, it is likely using 1433 already, so you will want to change the mapping.
  • We are telling Docker to automatically start the container when Docker starts – unless the container was stopped manually. Learn more about the other options here.
  • We are setting the password to the SQL ‘sa’ account. We will use this when connecting via SQL Management Studio. Important: The password must meet the password complexity requirements found here.

Note: refer to this article for some guidance on copying files and how to configure the container to use an external volume to store database files.

In the command prompt, type the following command to download and run SQL Express. Note: the image is 5GB and will extract after downloading.

docker run -d -p 1433:1433 --restart unless-stopped -e sa_password=<YOUR_PASSWORD> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express

Wait for the installation to complete before proceeding.

Confirm that the SQL Express container has started by running “docker ps” to show the running containers.

Next, we are going to connect to SQL Express using SQL Management Studio.

Download SQL Management Studio and connect to the SQL Express instance to verify it is working

Download SQL Management Studio if you don’t have it installed here. I just accepted all of the default settings during install.

Open SQL Management Studio once it is installed. We are going to set the following settings:

  • Server name: localhost
  • Authentication: SQL Server Authentication
  • Login: sa
  • Password: <THE_PASSWORD_SET_DURING_INSTALL>

Once logged in, you should be able to access the SQL Express instance through the Object Explorer on the left.

From here, you can create or attach databases. I may update this post with some details on how to attach databases and manage storage, but for now you can refer to this article for some guidance on copying files and how to configure the container to use an external volume.

Next, we are going to install Redis on Docker for Windows.

Download and start the Redis image

Run the following Docker command to download and start the Redis image. Learn more about the Redis image here.

In the Docker command below, we are configuring a few key settings:

  • We are mapping port 6379 on the local machine to 6379 on the Redis container in Docker. If you have Redis running on your local machine, it is likely using 6379 already, so you will want to change the mapping.
  • We are telling Docker to automatically start the container when Docker starts – unless the container was stopped manually. Learn more about the other options here.
  • We are configuring persistent storage for Redis with “–appendonly”
docker run --name dev-redis -p 6379:6379 --restart unless-stopped -d redis --appendonly yes

Confirm that the Redis container has started by running “docker ps” to show the running containers.

Next, we will install RedisInsights to verify the Redis instance is working.

Download and run Redis Insights to verify it is working

RedisInsight is a web-based GUI to browse and manage your Redis instances. It also gives you access to the Redis CLI. Learn more about it here.

Install RedisInsights here.

Open RedisInsights after it is installed. It will launch a web browser and we can follow the screenshots below to add our Redis instance.

Learn more about adding your Redis instance here.

instance_overview_page
instance_overview_page
instance_overview_page

Once it is added, select your Redis instance.

instance_overview_page

Test the Redis instance by setting/retrieving keys. Stop and start Docker to ensure the Redis container restarts and the keys are still available.

cli
Conclusion

Our mission to install SQL Express and Redis on Docker for Windows is complete.