WebStorm 2026.2 Help

Tutorial: Dockerize a Node.js Express app with a Redis database

You can use WebStorm to run and debug a Node.js Express application running in multiple Docker containers under Docker Compose.

This tutorial describes how to run two Docker Compose services inside containers in the same virtual network: a simple Node.js Express application and a Redis database.

In this tutorial, we will:

  • Create a Node.js Express application that implements a counter of HTTP requests and increments the counter in the database.

  • Write a Dockerfile for this application.

  • Create a DockerCompose file to connect two services - the counter application and a Redis database.

  • Build, deploy, and run an image of our application and a Redis image in docker containers.

  • Access the application in the browser and check that the counter actually increments on refreshing the page.

Before you start

  1. Make sure the JavaScript Debugger, Node.js, Node.js Remote Interpreter, and Docker required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to Managing plugins.

  2. Download, install, and configure Docker as described in Docker.

Create a Node.js application

  1. Click New Project on the Welcome screen or select File | New | Project from the main menu.

  2. In the dialog that opens, select Node.js in the left-hand pane.

  3. Specify the location of the application and its name, for example, counter.

  4. Specify the local Node.js runtime to use. Accept the suggested installation or select another one from the list, or even click Download if you do not have Node.js on your machine yet. Learn more from Create a new Node.js application.

    Create an empty project with Node.js
  5. Click Create.

WebStorm generates a project stub and opens it in the editor.

Populate the application

Our application will consist of one JavaScript file index.js.

  1. Open the Project tool window Alt+1, right-click the project folder, select New from the context menu, and then select JavaScript File.

    Create a new JavaScript file
  2. In the popup dialog that appears, specify the name of the file, for example, index.js.

    Create a new JavaScript file – specify the file name

    WebStorm creates a file index.js and opens it in the editor.

  3. In the index.js file, enter the following code:

    const express = require('express'); const redis = require('redis'); const app = express(); // The host name 'redis-server' will be specified in docker-compose.yml const client = redis.createClient({ url: 'redis://redis-server:6379' }); client.on('error', (err) => console.log('Redis Client Error', err)); app.get('/', async (req, res) => { try { // The `incr` command atomically increments the value stored at the key by 1. // If the key does not exist, it is created with the value 0 before the increment. const visits = await client.incr('visits'); res.send(`The number of visits is ${visits}`); } catch (err) { res.status(500).send('Error while accessing Redis'); } }); // First we connect to Redis, and then we run the server app.listen(3000, async () => { await client.connect(); console.log('Server running at port 3000'); });
  4. WebStorm detects that the Express framework and the client to work with Redis are missing and highlights the references to them as unresolved.

    Place the cursor at an unresolved reference, press Alt+Enter, and then select Install 'express' as dev dependency or Install 'redis' as dev dependency.

    Use a quick fix to install a dependency

Containerize the application

For Redis, we will use a ready image while for the Web part of our application we need to write a Dockerfile.

Create a Dockerfile

  1. From the context menu of the project folder, select New, and then select Dockerfile.

    Create a Dockerfile - context menu
  2. Open the newly created Dockerfile and type the following code:

    # Specify a light-weight Node.js image FROM node:22-alpine # Specify the working directory inside the container WORKDIR /usr/src/app COPY package*.json ./ RUN npm install --production COPY . . # Expose the container's port EXPOSE 3000 # Specify the command to launch application CMD ["node", "index.js"]

Now we have to bind two parts of our application via a docker-compose.yml file.

Create a docker-compose.yml file

  1. From the context menu of the project folder, select New and then select Docker Compose File.

    Create a docker-compose.yml

    In the popup that opens, accept the default Docker Compose file name or specify a custom one and press Enter.

    Create a docker-compose.yml
  2. Open the newly created docker-compose.yml and type the following code:

    services: redis-server: image: redis:alpine web: # The build directive instructs Docker Compose to build # an image of our application based on the Dockerfile # from the current folder build: . # Bind the local port with port inside the container ports: - "3000:3000" # The depends_on directive ensures that # the container starts after the redis-server depends_on: - redis-server

Run the application

  • In the docker-compose.yml, click docker-compose up gutter icon next to services and select Run on Docker from the context menu to run the docker compose up -d command.

    Run docker-compose

WebStorm first starts the redis-server Docker Compose service and makes sure that the database is healthy. Then it starts the web service. If everything is correct, you should see the following in the Services tool window:

Services tool window with two containers running

If you click counter-web-1 under the web node, you will see the Server running at port 3000 output:

Application output in the console

Check whether the application works as expected

  1. Open the browser at http://localhost:3000. The page opens showing The number of visits is 1.

  2. Refresh the page several times to see that the counter increments.

26 June 2026