Docker: Basic understanding and terminology
History: how did it is originated?
Solomon Hykes originated from Paris founded the docker as DotCloud in 2008. And initially, it is started as a Platform as a service (PaaS). Later, he started to focus on democratizing the underlying software containers on which its platform was running. Hykes first demoed the Docker at PyCon in March 2013. And he explained that Docker was created because developers kept asking for the underlying technology powering the DotCloud platform.
Finally, Docker was born as an open-source project and quickly pick up the interest of the developers. Many big organizations like Microsoft, IBM, Red Hat funded this initiative to make the boom. The container revolution had begun.
Definition: what is a docker?
Docker is an operating system virtualized software platform that allows the developers to create, run and deploy the applications easily in dockerized containers with necessary dependencies and configuration. The container is a lightweight package that consists of all the needed dependencies and configurations such as libraries, frameworks, and bins within itself.
Docker Architecture
Components of Docker: Terminology
Docker Client
It is the command-line instructed solution to issue the commands from the Docker client to the Docker daemon. The communication takes place through REST API between the Docker client and the Docker daemon. When we try to issue the commands using the terminal. Then the instruction sends to the daemon and the operation performs by interacting with other components like the registry, server.
Docker Server
Docker daemon represents the Docker server used to interact with the operating system and perform services. It continuously listens across the REST API to accomplish the instructions. This will let you know the services on your host using the docker commands.
Docker Image
It is a template that contains the instructions for the Docker container. The image is written in a YAML language (Yet Another Markup Language) and then hosted as a file in the Docker registry. The image consists of different layers and each layer is dependent on the below it. These layers are created by executing the command in the Dockerfile.
Let’s see an example of a Docker image:
## syntax
## how to create docker image
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
Docker Registry
The registry is the place where you can host various kinds of images and provide the images to use from here. It is the collection of the Docker images that are built on the instructions written in YAML to store and share easily. We provide the tag names with the images so that developers could easily find them. The repositories can be private and public, Docker manages a public repository publicly accessible know as the Docker hub.
The commands used to connect with the repository are push and pull.
- Push command to push the locally created container from the local manager node to the Docker registry
- Pull command to retrieve existing new clients (Docker image) to the local machine from the Docker registry.
Docker Container
Docker container is an executable package of the applications with necessary dependencies and configuration. It is lightweight due to the built-in structural redundancy. The containers run completely in isolation and are portable. The memories of a Docker environment can be shared across multiple containers, it is very useful for limited memory usage or storage.
Docker Network
Docker network is one of the most powerful concepts of docker. It gives the freedom and reliability to run multiple containers (services) on the same network. Docker network is a network. Docker containers and services do not even need to be aware that they are deployed on Docker, or whether their peers are also Docker workloads or not. Whether your Docker hosts run Linux, Windows, or a mix of the two, you can use Docker to manage them in a platform-agnostic way.
Let’s see an example of a Docker network:
######## creating a netwrok to run multiple services/containers on the same ######## network
## create a network (docker)
docker network create host-network
## start mongodb
docker run -d \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=password \
--net host-network \
-- name mongodb \
mongo
## start mongo-express
docker run -d \
- p 8081:8081 \
- e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
- e ME_CONFIG_MONGODB_ADMINPASSWORD=password \
- e ME_CONFIG_MONGODB_SERVER=mongodb \
-- net host-network \
-- name mongo-express \
mongo-express
Docker Compose
Docker-compose is designed for running multiple containers as a single service. It is a very useful concept to run the containers in isolation and allow them to interact with each other. This docker-compose is written in YAML.
Let’s see an example of Docker compose:
## Docker-compose file to multiple containers as single service
version:'3'
services:
mongodb:
image:mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
mongo-express:
image:mongo-express
ports:
- 8080:8080
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb
Docker Swarm
It is a service for the containers that allows IT, administrators, and developers, to create and manage a cluster of swarm nodes within the Docker platform. Each node of the Docker swarm is a Docker daemon, and all Docker daemons interact using the Docker API. It has two types of nodes:
- Manager node: that manages or maintains the cluster management tasks.
- Worker node: that receives and executes tasks assigned from the master node.
Basic and important commands of Docker:
## To show all the running docker containers
docker ps
## To show all the stopped and running docker containers
docker ps -a
## To pull the images from public repository
docker pull image_name
## To run the docker image
docker run image_name
## To check all the images of the host
docker images
## To start the container
docker start container_id
## To stop the container
docker stop container_id
## To remove/delete the container
docker rm container_id
## To remove/delete the image
docker rmi image_id
## To stop all the running containers
docker stop $(docker ps -a -q)
## To remove/delete all the containers
docker rm $(docker ps -a -q)
## To build docker image for your service
docker build -t my_docker_image:1.0
## To run the built docker image for your service
docker run my_docker_image:1.0
## To create docker network
docker network create network_name
## To bind the host port and container port while running container
## host-port=4500
## container-port=4000
docker run -p4500:4000 image_name
## To check the logs of the container
docker logs container_id
docker logs container_name
## To open the interactive terminal for specific container
docker exec -it container_id /bin/bash
docker exec -it container_id bash
## To list out all the docker networks
docker network ls
## To create docker network
docker network create network_name
## To run the docker-compose file
docker-compose -f filename.yaml up
## To stop the docker-compose file
docker-compose -f filename.yaml down
Reference
This blog helps you to understand the basics of Docker and its terminology. For more detailed information, please visit this link. In case you want to install the docker on ubuntu 20.04, you can refer to this link.