Basics of Docker


Docker Engine

Verify docker installation

docker run hello-world
  • Logs show image doesn’t exists in the local docker repository and hence docker service downloaded the image from the docker hub repository to run the container.

Run docker container with startup command

docker run busybox echo "Running busybox container"

Docker Execution Flow

  • Docker client
  • Docker service
  • Docker registry ( local repository and remote repository: docker hub)
  • Container image
  • Container
  • Docker client exposes docker service APIs with commands.
  • When we executed the docker run command on the Docker client, it invokes the docker service API for running the container.
  • Docker service can be on the same machine as the docker client or can be on the remote machine.
  • Docker service will check if the docker busy box image already exists in the local repository. You can consider a local repository as a cache.
  • If the local docker repository doesn’t contain the busybox image then the docker service will download the image from the docker hub.
  • Docker service will create a container out of the busy box image.
  • As soon as the container is ready, the container will run a start-up command.

Run any docker image

docker run <docker_image_name>
docker run <image_name>:<tag>


Create a node app

Docker Process

Package app into image

FROM node: 10
ADD node-js-example.js /app.js
ENTRYPOINT ["node", "app.js"]
  • FROM defines the base image.
  • ADD will add file node-js-example.js to container image with name app.js
  • ENTRYPOINT specifies the command that will be executed when container starts up.
docker build -t mynodeapp .
  • Docker client uploads complete build directory to the docker service.
  • Docker service build image by executing the instructions mentioned in the docker file.
  • It stores the generated image in the local docker repository.

List Images

docker images

Run docker container

docker run --name mynodeapp-container -p 8080:8080 -d mynodeapp
  • name : Name of the container
  • p : Map application port to the container port
  • d : Name of the container image

List containers

docker ps
docker ps -a
docker inspect mynodeapp-container

Look into running container

docker exec -it mynodeapp-container bash
ps aux

Stop and Remove container

docker stop mynodeapp-container
docker rm mynodeapp-container



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