Prerequisites

This article assumes that the docker-ce is installed and the daemon is running.



Nginx server as a container


Run the following command to get the Nginx Docker image:

  • docker pull nginx
 

This downloads all the necessary components for the container. Docker will cache these, so when we run the container we don’t need to download the container image(s) each time. These images can either be stored in a private container registry or by default it would be downloaded from Docker Hub. Docker has official image for Nginx and also it has an in-built support for ARM 64 which is at the heart of B1000N.



Docker maintains a site called Dockerhub, a public repository of Docker files (including both official and user-submitted images). The image we downloaded is the official Nginx one, which saves us from having to build our own image.

Let’s start our Nginx Docker container with this command:

  • docker run -d --name docker-nginx -p 8080:80 nginx
 
  • run is the command to create a new container
  • -d specifies to run the container in background i.e., in daemon mode
  • The --name flag is how we specify the name of the container (if left blank one is assigned for us, like nostalgic_hopper from Step 2)
  • -p specifies the port we are exposing in the format of -p local-machine-port:internal-container-port. In this case we are mapping Port 80 in the container to Port 80 on the server
  • nginx is the name of the image on dockerhub (we downloaded this before with the pull command, but Docker will do this automatically if the image is missing)


This is all that is requried to get Nginx running. Paste the IP address of your machine into a web browser and you should see Nginx’s “Welcome to nginx!” page:


We can verify the container running in the background by this with this command:

  • docker ps -a
 

You should see something similar to the output shown below:

Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3dc6db4c7924 nginx "/docker-entrypoint.…" 21 hours ago Up 21 hours 0.0.0.0:8080->80/tcp docker-nginx

We can see that our Docker container running in the background.


Remove the existing docker-nginx container with this command:

  • docker rm docker-nginx