41

Docker: Components

 2 years ago
source link: https://blog.knoldus.com/docker-components/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Reading Time: 5 minutes

Docker is an open-source software platform. It is designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts which are required, such as libraries and other dependencies and ship it all out as one package. In this blog, we are going to discuss the Docker Components

Image result for Docker ComponentsDocker Components

These are the Docker Components:

DOCKER CLIENT

The Docker client enables users to interact with Docker. 

Docker runs in a client-server architecture that means docker client can connect to the docker host locally or remotely. Docker client and host (daemon) can run on the same host or can run on different hosts and communicate through sockets or a RESTful API. 

The Docker client is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the client sends these commands to docker daemon, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.

We can communicate with the docker client using the Docker CLI. We have some commands through which we can communicate the Docker client. Then the docker client passes those commands to the Docker daemon.

docker build ...
docker run ...
docker push ..
etc.

DockerHost

The Docker host provides a complete environment to execute and run applications. It includes Docker daemon, Images, Containers, Networks, and Storage.

Docker Daemon

Docker Daemon is a persistent background process that manages Docker images, containers, networks, and storage volumes. The Docker daemon constantly listens for Docker API requests and processes them.

When you use a docker run command to start up a container. Your docker client will translate that command into an HTTP API call, sends it to docker daemon. Docker daemon then evaluates the request, talks to underlying os and provisions your container.

The daemon is responsible for all container-related actions and receives commands via the CLI or the REST API. It can also communicate with other daemons to manage its services. The Docker daemon pulls and builds container images as requested by the client.

Docker Images:

Docker Components: DockerfileDocker Components

Docker-images are a read-only binary template used to build containers. Images also contain metadata that describe the container’s capabilities and needs.

Create a docker image using the docker build command. whenever you pass a Dockerfile to the docker build command then the docker daemon will create a docker image according to the Dockerfile instruction.

Run the docker images using the docker run command. whenever we pass the command to docker client then the docker client passes this command to the docker daemon then docker daemon will create the container for that image.

Push the docker image to the public registry like DockerHub using the docker push command after pushed you can access these images from anywhere using docker pull command.

An image can be used to build a container. Container images can be shared across teams within an enterprise using a private container registry, or shared with the world using a public registry like Docker Hub.

Docker Containers:

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

Containers provide you with a lightweight and platform-independent way of running your applications. Every container is isolated but access to resources on another host or container can be allowed with the help of docker networking.

A container is volatile it means whenever you remove or kill the container then all of its data will be lost from it. If you want to persist the container data use the docker storage concept.

Containers only have access to resources that are defined in the image, unless additional access is defined when building the image into a container.

Docker Networking

Through the docker networking, we can communicate one container to other containers.

By default, you get three different networks on the installation of Docker – none, bridge, and host. The none and host networks are part of the network stack in Docker. The bridge network automatically creates a gateway and IP subnet and all containers that belong to this network can talk to each other via IP addressing.

The other type of networks is user-defined networks. Administrators can configure multiple user-defined networks. There are three types:

  • Bridge network: a user-defined Bridge network differs in that there is no need for port forwarding for containers within the network to communicate with each other.
  • Overlay network: An Overlay network is used when you need containers on separate hosts to be able to communicate with each other, as in the case of a distributed network.
  • Macvlan network: When using Bridge and Overlay networks a bridge resides between the container and the host. A Macvlan network removes this bridge, providing the benefit of exposing container resources to external networks without dealing with port forwarding. This is realized by using MAC addresses instead of IP addresses.

Docker Storage

A container is volatile it means whenever you remove or kill the container then all of its data will be lost from it. If you want to persist the container data use the docker storage concept.

You can store data within the writable layer of a container but it requires a storage driver. In terms of persistent storage, Docker offers the following options:

  • Data Volumes: Data Volumes provide the ability to create persistent storage, with the ability to rename volumes, list volumes, and also list the container that is associated with the volume. Data Volumes sit on the host file system, outside the containers copy on write mechanism and are fairly efficient.
  • Data-Volume Container: A Data Volume Container is an alternative approach wherein a dedicated container hosts a volume and to mount that volume to other containers. In this case, the volume container is independent of the application container and therefore can be shared across more than one container.
  • Bind Mounts: Another option is to mount a host’s local directory into a container. In the previously mentioned cases, the volumes would have to be within the Docker volumes folder, whereas when it comes to Directory Mounts any directory on the Host machine can be used as a source for the volume.

Docker Registries

Docker Components: Image result for docker registryDocker Components

Docker-registries are services that provide locations from where you can store and download images.

In other words, a Docker registry contains repositories that host one or more Docker Images.

Public Registries include Docker Hub and Docker Cloud and private Registries can also be used. You can also create your own private registry.

Push or pull image from docker registry using the following commands

docker push
docker pull
docker run

That’s all for now, I will follow it up with more knowledge on this topic next time.

Thank you for sticking to the end. If you like this blog, please do show your appreciation by giving thumbs ups and share this blog and give me suggestions on how I can improve my future posts to suit your needs. Follow me to get updates on different technologies

References:

knoldus Bottom Image


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK