Node.js Web Server Deployed within Docker

Updated by Linode Written by Joe D.

Contribute on GitHub

Report an Issue | View File | Edit File

Node.js is a server-side, JavaScript package, often used for various cloud applications. Docker is a container platform. With Docker, users can download applications without the hassle of the installation and configuration process.

Install Docker

These steps install Docker Community Edition (CE) using the official Ubuntu repositories. To install on another distribution, see the official installation page.

  1. Remove any older installations of Docker that may be on your system:

    sudo apt remove docker docker-engine
  2. Make sure you have the necessary packages to allow the use of Docker’s repository:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
  3. Add Docker’s GPG key:

    curl -fsSL | sudo apt-key add -
  4. Verify the fingerprint of the GPG key:

    sudo apt-key fingerprint 0EBFCD88

    You should see output similar to the following:

    pub   4096R/0EBFCD88 2017-02-22
            Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
    uid                  Docker Release (CE deb) 
    sub   4096R/F273FCD8 2017-02-22
  5. Add the stable Docker repository:

    sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
    For Ubuntu 19.04 if you get an E: Package 'docker-ce' has no installation candidate error this is because the stable version of docker for is not yet available. Therefore, you will need to use the edge / test repository.
    sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable edge test"
  6. Update your package index and install Docker CE:

    sudo apt update
    sudo apt install docker-ce
  7. Add your limited Linux user account to the docker group:

    sudo usermod -aG docker $USER
    After entering the usermod command, you will need to close your SSH session and open a new one for this change to take effect.
  8. Check that the installation was successful by running the built-in “Hello World” program:

    docker run hello-world

Download the Docker Node.js Server Image

The Docker Hub user page for Linode can be accessed here. Select the server-node-js image for configuration information.

Docker images made for one operating system can be used on servers running a different OS. The server-node-js Ubuntu 14.04 image was tested on Debian 7, Ubuntu 14.04, CentOS 7 and Fedora 21. After Docker installation on CentOS and Fedora, run the sudo service docker start command.
  1. Search for linode images:

    docker search linode
  2. Download the linode/server-node-js image:

    docker pull linode/server-node-js

Run the Docker Container, Node.js, and the Web Server

  1. Run the Linode container. Forward the Linode’s port 80 to port 3000 of the container:

    docker run -d -p 80:3000 linode/server-node-js
    This command runs the docker image as a daemon.
  2. Test the server at, replacing with your Linode’s IP address. A page with “Test File” should appear.

The Docker Hub image page has information explaining what the Docker image contains.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.