Difficulty: Beginner
Estimated Time: 10 minutes

This scenario continues to explore how to build and deploy your applications as a Docker container. The previous scenario covered deploying a static HTML website. This scenario explores how to deploy a Node.js application within a container.

The environment is configured with access to a personal Docker instance, and the code for a default Expressjs application is in the working directory. To view the code use ls and cat <filename> or use the editor.

The machine name Docker is running on is called docker. If you want to access any of the services then use docker instead of localhost or

Based on blog post by Ben Hall

This course explored how you can build a Dockerfile for deploying Node.js applications.

Don’t stop now! The next scenario will take about 20 minutes to complete. You can pause and come back at any time.

Dockerizing Node.js applications

Step 1 of 5

Step 1 - Base Image

As we described in the previous scenario, all images started with a base image, ideally as close to your desired configuration as possible. Node.js has pre-built images available with tags for each released version.

The image for Node 7.0 is node:7-alpine. This is an Alpine-based build which is smaller and more streamlined than the official image.

Alongside the base image, we also need to create the base directories of where the application runs from. Using the RUN <command> we can execute commands as if they're running from a command shell, by using mkdir we can create the directories where the application will execute from. In this case, an ideal directory would be /src/app as the environment user has read/write access to this directory.

We can define a working directory using WORKDIR <directory> to ensure that all future commands are executed from the directory relative to our application.

Task: Define Base Environment

Set the FROM <image>:<tag>, RUN <command> and WORKDIR <directory> on separate lines to configure the base environment for deploying your application.