DEV Community

Cover image for Introduction to Docker
Parul Chaddha
Parul Chaddha

Posted on

Introduction to Docker

Docker is a set of platforms as a service (PaaS) products that use the Operating system level virtualization to deliver software in packages called containers.

This is something a typical definition but let's understand it in simple terms.

Think of Docker as a delivery service for software. It helps package up software and everything it needs to run into a neat box called a "container."
Each container is like a separate box that holds a specific piece of software. These boxes are very good at keeping things separate and organized.
Inside each container, you'll find the software, the tools it needs to work, and even its own settings. It's like the software's own little world.
These containers can talk to each other if they need to. They have clear rules on how to communicate, like different rooms in a house connected by hallways.
The clever part is that all these containers share the same "house" (the operating system), which makes it efficient. It's like living in an apartment building where everyone shares the same building but has their separate apartments.

*Important Terminologies in Docker *

1. Docker Image

  • It is a file, comprised of multiple layers, used to execute code in a Docker container.
  • They are a set of instructions used to create docker containers. Simple terms explanation: Think of a Docker image as a snapshot of a software application. It's like taking a picture of a cake recipe, all the ingredients, and how to bake it.

2. Docker Container

  • It is a runtime instance of an image.
  • Allows developers to package applications with all parts needed such as libraries and other dependencies. Simple terms explanation: A Docker container is like a single, ready-to-eat cake made from the cake recipe image. It's a running instance of a Docker image.

3. Docker file

  • It is a text document that contains necessary commands which on execution helps assemble a Docker Image.
  • Docker image is created using a Docker file. Simple terms explanation: Think of a Dockerfile as the list of steps to make the "cake recipe image." It's like writing down all the ingredients and instructions.

4. Docker Engine

  • The software that hosts the containers is named Docker Engine.
  • Docker Engine is a client-server based application The docker engine has 3 main components: Server: It is responsible for creating and managing Docker images, containers, networks, and volumes on the Docker. It is referred to as a daemon process. REST API: It specifies how the applications can interact with the Server and instructs it what to do. Client: The Client is a docker command-line interface (CLI), that allows us to interact with Docker using the docker commands. Simple terms explanation: The Docker Engine is like the chef in the kitchen. It's the software that creates and manages containers.

5. Docker Hub

  • Docker Hub is the official online repository where you can find other Docker Images that are available for use.
  • It makes it easy to find, manage, and share container images with others. Simple terms explanation: Docker Hub is like an online cookbook where you can find many "cake recipes" (Docker images) created by others. It's a place to share and discover recipes.

Features of Docker:

  • Open-source platform
  • An Easy, lightweight, and consistent way of delivery of applications
  • Fast and efficient development life cycle.
  • Segregation of duties
  • Service-oriented architecture
  • Security
  • Scalability
  • Reduction in size
  • Image management
  • Networking
  • Volume management

Architecture of Docker

The Docker client talks with the docker daemon which helps in building, running, and distributing the docker containers. With the help of REST API over a UNIX socket or a network, the docker client and daemon interact with each other.

What is Docker Daemon?
Docker daemon manages all the services by communicating with other daemons. It manages docker objects such as images, containers, networks, and volumes with the help of the API requests of Docker.

Docker Client
With the help of the docker client, the docker users can interact with the docker. The docker command uses the Docker API. The Docker client can communicate with multiple daemons. When a docker client runs any docker command on the docker terminal then the terminal sends instructions to the daemon. The Docker daemon gets those instructions from the docker client withinside the shape of the command and REST API’s request. The common commands which are used by clients are docker build, docker pull, and docker run.

Docker Host
A Docker host is a type of machine that is responsible for running more than one container. It comprises the Docker daemon, Images, Containers, Networks, and Storage.

Docker Registry
All the docker images are stored in the docker registry. There is a public registry which is known as a docker hub that can be used by anyone. We can run our private registry also. With the help of docker run or docker pull commands, we can pull the required images from our configured registry. Images are pushed into configured registry with the help of the docker push command.

Docker Storage
We can store data within the writable layer of the container but it requires a storage driver. Storage driver controls and manages the images and containers on our docker host.

Docker Cloud

Docker Cloud is basically working as a service provider by Docker in which we can perform such as Operation system agnostic, packing only what is needed to run the application in an efficient manner, and easily moving to interact between infrastructure, among many others.

Operations of Docker Cloud

  • Nodes:– Connection between the cloud services provider such as MS Azure and AWS to run up containers.
  • Data Processing:– Provide big data processing as a service package.
  • Cloud Repository:– Provide a platform where we can store a number of versions in a specific Docker Image.
  • Continuous Implementation:– Connect with GitHub and build a continuous integration pipeline.
  • App Deployment:– Scale the Infrastructure and Containers with deployment.
  • Consist Deployment:– it can be automated deployment.

Docker Commands

Docker Run
This command is used to run a container from an image. The docker run command is a combination of the docker create and docker start commands.

$ docker run <image_name>
To give name of container
$ docker run --name <container_name> <image_name>
Enter fullscreen mode Exit fullscreen mode

Docker Pull
This command allows you to pull any image which is present in the official registry of docker, Docker hub. By default, it pulls the latest image, but you can also mention the version of the image.

$ docker pull <image_name>
Enter fullscreen mode Exit fullscreen mode

Docker PS
This command (by default) shows us a list of all the running containers. We can use various flags with it.

  • -a flag: shows us all the containers, stopped or running.
  • -l flag: shows us the latest container.
  • -q flag: shows only the Id of the containers.
$ docker ps [options..]
Enter fullscreen mode Exit fullscreen mode

Docker Stop
This command allows you to stop a container if it has crashed or you want to switch to another one.

$ docker stop <container_ID>
Enter fullscreen mode Exit fullscreen mode

Docker Start
Suppose you want to start the stopped container again, you can do it with the help of this command.

$ docker start <container_ID>
Enter fullscreen mode Exit fullscreen mode

Docker rm
To delete a container.
Some important flags:

  • -f flag: remove the container forcefully.
  • -v flag: remove the volumes.
  • -l flag: remove the specific link mentioned.
$ docker rm {options} <container_name or ID>
Enter fullscreen mode Exit fullscreen mode

Docker Images
Lists all the pulled images which are present in our system.

$ docker images
Enter fullscreen mode Exit fullscreen mode

Docker Login
The Docker login command will help you to authenticate with the Docker hub by which you can push and pull your images.

$ docker login 
Enter fullscreen mode Exit fullscreen mode

Docker Push
Once you build your own customized image by using Dockerfile you need to store the image in the remote registry which is DockerHub for that you need to push your image by using the following command.

docker push <Image name/Image ID> 
Enter fullscreen mode Exit fullscreen mode

Docker Build
The docker build command is used to build the docker images with the help of Dockerfile.

docker build -t image_name:tag .
Enter fullscreen mode Exit fullscreen mode

In the place of image_name use the name of the image you build with and give the tag number and . “dot” represents the current directory.

Docker Stop
You can stop and start the docker containers where you can do the maintenance for containers. To stop and start specific containers you can use the following commands.

docker stop container_name_or_id
Enter fullscreen mode Exit fullscreen mode

Stop Multiple Containers
Instead of stopping a single container. You can stop multiple containers at a time by using the following commands.

docker stop container1 container2 container3
Enter fullscreen mode Exit fullscreen mode

Docker Restart
While running the containers in Docker you may face some errors and containers fails to start. You can restart the containers to resolve the containers by using the following commands.

docker restart container_name_or_id
Enter fullscreen mode Exit fullscreen mode

Docker Inspection
Docker containers will run into some errors in real time to debug the container’s errors you can use the following commands.

docker inspect container_name_or_id
Enter fullscreen mode Exit fullscreen mode

Docker Commit commands
After running the containers by using the current image you can make the updates to the containers by interacting with the containers from that containers you can create an image by using the following commands.

docker commit container_name_or_id new_image_name:tag
Enter fullscreen mode Exit fullscreen mode

This blog has covered up almost all the basics of Docker.
Hope you liked it .😊😇

Top comments (0)