Node.js Web Server Deployed within Docker
Updated by Linode Written by Joe D.
At the time of writing, the recommended Docker installation is Docker CE. Remove any older installations of Docker that may be on your system:
apt remove docker docker-engine docker.io
Make sure you have the necessary packages to allow the use of Docker’s repository:
apt install apt-transport-https ca-certificates curl software-properties-common
Add Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify the fingerprint of the GPG key:
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) <firstname.lastname@example.org> sub 4096R/F273FCD8 2017-02-22
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Update your package index and install Docker CE:
apt update apt install docker-ce
Add your limited user account to the
usermod -aG docker exampleuser
You will need to restart your shell session for this change to take effect.
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.
NoteDocker 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 startcommand.
Search for linode images:
docker search linode
Download the linode/server-node-js image:
docker pull linode/server-node-js
Run the Docker Container, Node.js, and the Web Server
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
NoteThis command runs the docker image as a daemon.
Test the server at
example.comwith 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.
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.
- How to install Docker and deploy a LAMP Stack - Deprecated
- SSL Certificates with Apache on Debian & Ubuntu
- How to Configure a Firewall with UFW
- Apache Web Server on Ubuntu 14.04 LTS
- Apache Web Server on Debian 8 (Jessie)
This guide is published under a CC BY-ND 4.0 license.