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:

Our web app is up and running on port 8080

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

Similar Reads

What is Docker Image?

A docker image is a static file that is used to make a docker container. It acts like a template, that contains set of instructions, application code, dependencies and libraries to build and run a container instance. A docker image is created by using a file called Dockerfile. The Dockerfile contains instructions that are required to create a docker image....

What are Docker Containers?

Docker containers are runtime instances of docker images. They are very lightweight, and share the kernel of the host OS. These are the places where the actual application code is being executed and all the dependencies, libraries, environment variables required for the application are present inside them. Containers are created by running a docker image. Docker image acts as a executable, on executing which, we get docker containers....

What is Docker Container Create?

Docker Container Create is a command in the docker that helps in creating new container instances with the specified Docker images. It initialize the container by setting up all the essential environments for this quickly and effectively but it not start the docker container. It facilitates the developers to isolate the applications and their dependencies from the other containerized applications....

Description

Docker container create facilitates with instantly preparing a new container for the specified image. It setup the environment required to launch the container. It configure the container in advance by allocating the namespaces, hostname, filesystem, networks, volumes, variables and other that defined in the Dockerfile or command-line options....

Docker Container Create Options

The following are the options that are available with Docker Container Create:...

Examples of Docker Container Create

The following are the examples of Docker Container Create with different options:...

How to Build A Docker Container Image? A Step-By-Step Guide

The following are the steps for building the Docker Container Image:...

How to Create Docker Containers from Docker Images? A Step-By-Step Guide

To create docker containers from a docker image, first we must have a docker image. We can get our required docker image either from Dockerhub, or can create our custom docker image by using a Dockerfile. After we have our required docker image, follow the following steps:...

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:...

Build, Name and Tag the Docker Container Images

The following are the commands we are going to discuss on building, Name and Tag the docker container Images:...

Running And Viewing Docker Containers

The following are the commands used for running and viewing the Docker Containers:...

TroubleShooting of Docker Container Create

The following are the some of the Trouble Shooting Issues of the Docker Container Create:...

Docker Container Create – FAQs

What is Docker Container Create User?...