Image for post
Image for post

With Docker, developers can build any app in any language using any tool-chain. “Dockerized” apps are completely portable and can run anywhere on OS X and Windows laptops, QA servers running Ubuntu in the cloud, and production data center VMs running Red Hat.

Developers can get going quickly by starting with one of the 1,00,000+ apps available on Docker Hub. Docker manages and tracks changes and dependencies, making it easier for sysadmins to understand how the apps that developers build work. And with Docker Hub, developers can automate their build pipeline and share artifacts with collaborators through public or private repositories.

Docker helps developers build and ship higher-quality applications, faster.— What is Docker

Need for Docker

  1. Many times we have observed that when a new developer joins our team then he took almost half a day to set up his development environment. Similarly, when we want to run our application on some machine we need to take care of all those dependencies before running it.

Components of docker:

Docker is becoming complex day by day because of cloud requirements then from where to start.

  1. Docker Host — This is an area inside any host machine where Docker is installed. Where all our containers will run or reside.
Image for post
Image for post
Docker architecture

Let’s try to understand from one end which is our application and we can go till the cloud.

  1. Dockerfile — This is the file we do add inside of the project root folder. Which holds the information about what project needs to run. Along with instructions so that along with our project build or source code other dependencies should be added in the final image.
FROM node:12RUN mkdir -p /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000CMD [“npm”, “start”]Let’s understand each and every line.

FROM node:12 :

  1. this line informs the docker host that Take node:12 as the base image.

RUN mkdir -p /app

  1. We want docker to create an “app” folder. Our intention is to put our app related data there.


  1. We are mentioning that the “app” directory will be my working directory now onwards.

COPY package.json .

  1. We are copying the package.json file in the current working directory that is “app” now. Why we are copying it. because the package.json file holds all those dependencies needed for the application. Using the next command we are going to install all those dependencies required for our application. But in your app, there are chances of not having such a file. Then whatever dependencies you need you can mention one by one in the Docker file.

RUN npm install

  1. Here we are instructing the docker host to install those packages which are mentioned in package.json.

COPY . .

  1. Here we are copying all our applications in that working directory. This is okay for development purposes but while making an image for deployment we need to copy only the build folder and required packages.


  1. This application runs on localhost:3000 but when this application will run on the docker host then the 3000 port of our machine and 3000 port of the docker container should be mapped so we are exposing our port so that the host machine should forward the request coming to 3000 port to our container.

CMD [“npm“, “start“]

  1. This is the command to run that image. When their time comes to run the image.

Docker Image

  1. We tried to understand what a docker file is and what it’s purpose. When we build this dockerfile using the docker build command then the docker image gets created. Which is an executable image or we can say it is our application with all dependencies bundled. (it is executable but still, it is not running). Then when and how it will run?. here Docker container comes in a picture.

Docker Container

  1. Container is a place where our image or application is being executed. Now we can interact with the application or we can see the application on the browser using localhost:3000.

Commands for image and container creation

  1. Assuming you have written Dockerfile. Now be inside the folder where Dockerfile resides and fire the below command from the terminal.
docker build -f Dockerfile -t <projectname> .
  1. -f: Here -f is from the file we can use — file also.

Commands to run image and container

docker run — name auth-tool -p 3000:3000 MyWebApp:1.0
  1. — name: is for the name of the container

Unanswered questions

  1. How to handover that image to another person.

We will answer all those questions in the next chapter with some hands-on.

Software Engineer. (Mobile and Web)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store