Example of Running a Nodejs Web App Docker Image
In this example, we will see a NodeJS docker image getting contanerized by the docker run command. Here are the steps to do it:
Step 1: List all the docker images, that are available locally. Enter the following command to do this:
docker images
Output:
Step 2: In this example, we wann run the first docker image, which is a NodeJS application. It’s the kartikkala/mirror_website. So we will copy it’s image ID and run it with the necessary volume mounted and port 8080 mapped with the host PC. We are mapping port 8080 as it’s programmed in the NodeJS app to listen at port 8080. To know which port you need to map to the host PC, you can refer to this article – Managing Ports
Command:
docker run -p 8080:8080 -d --mount type=bind,src=$(pwd)/../volume1,dst=/downloadables kartikkala/mirror_website:beta
So you can see, there are a bunch of things going on here:
- First thing, port 8080 of the container is exposed to port 8080 of the host machine with the ‘ -p ‘ flag.
- Second thing, volume1 directory is bind mounted as a volume on /downloadables folder, where volume1 folder is of the host machine, and /downloadables is inside the container. This will cause all the changes inside the /downloadables folder to be reflected in the the volume1 folder directly.
Step 3: Now we will open up our browser and check on localhost or any other IP address assosicated with out local machine. Below is the screenshot for our web app running in the browser:
Output:
How To Create a Docker Container from an Existing Image?
Docker is an open-source software, that is used to contanerize our applications. Containerizing applications makes deployment a lot easier. For containerizing applications, docker uses Docker images, which act like templates for making containers. Today we will learn how to create a container from an existing Docker image, but before that, let’s take a quick look at What are Docker images and containers.
Table of Content
- What is Docker Image?
- What are Docker Containers?
- What is Docker Container Create?
- Description
- Docker Container Create Options
- Examples of Docker Container Create
- How to Build A Docker Container Image? A Step-By-Step Guide
- How to Create Docker Containers from Docker Images? A Step-By-Step Guide
- Example of Running a Nodejs Web App Docker Image
- Build, Name and Tag the Docker Container Images
- Running And Viewing Docker Containers
- TroubleShooting of Docker Container Create
- Docker Container Create – FAQs