The core concept and configuration of Docker

Key concept

1. Docker image

DockerThe image is similar to the virtual machine image and can be understood as a read-only template .
Mirroring is to create a Dockerbase of the container.
Through version management and incremental file system, it Dockerprovides a very simple mechanism to create and update existing mirrors. Users can even download a ready-made application mirror from the Internet and use it directly.

2. Docker container

DockerThe container is similar to a lightweight sandbox, Dockerusing containers to run and isolate applications .
A container is an application running instance created from an image. It can start, start, stop, and delete, and these containers are isolated from each other and invisible to each other.

3. Docker warehouse

DockerWarehouse similar code repository is Docker centralized place to store the image file .
According to whether the stored images are publicly shared or not, Docker warehouses can be divided into two forms : public warehouses (Public) and private warehouses (Private).

After the user has created his own image, he can use the push command to upload it to the designated public or private warehouse. In this way, next time the user uses the image on another machine, he only needs to pull it from the warehouse.

Install Docker engine

Currently, Docker supports multiple services such as Docker Engine , Docker Hub , and Docker Cloud .

  • Docker engine : including support for installing Docker on desktop systems or cloud platforms, and providing enterprises with simple, secure and flexible container cluster orchestration and management;
  • Docker Hub : the official cloud hosting service, which can provide public or private image warehouses;
  • DockerCloud : The official container cloud service that can complete the deployment and management of containers, can fully support containerized projects, and has CI and CD functions.

Install Docker in CentOS

First of all, in order to facilitate the addition of software sources and support the devicemapper storage type, install the following software packages:

sudo yum update
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 

Add the yum software source of the stable version of Docker:

sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

Then update the yum software source cache and install Docker:

sudo yum update
sudo yum install -y docker-ce

Finally, confirm that the Docker service starts normally:

sudo systernctl start docker

Configure Docker service

In order to avoid the need to switch to a privileged identity every time you use Docker commands, you can add the current user to the installation

  • The automatically created docker user group, the code is as follows:
sudo usermod -aG docker USER NAME
  • The user updates the group information, it will take effect after logging out and logging in again.

When the Docker service starts, it actually calls the dockerd command , which supports a variety of startup parameters. Therefore, the user can directly start the Docker service by executing the dockerd command, such as the following command to start the Docker service, turn on the Debug mode, and monitor the local port 2376:

dockerd -D -H tcp://127.0.0.1:2376

These options can be written into the daemon.json file under the /etc/docker/ path, and read when the dockerd service starts:

{
	"debug": true,
	"hosts":[" tcp://127.0.0 . 1:2376 ”]
}

Of course, the operating system also encapsulates the Docker service. Take the Ubuntu system that uses Upstart to manage the startup service as an example. The default configuration file of the Docker service is Ietc/default/dockerthat you can DOCKER OPTSmodify the service startup parameters by modifying it , for example, let the Docker service start Monitoring of network port 2375:

DOCKER_OPTS="$DOCKER_OPTS -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock”

After modification, restart the Docker service through the service command:

sudo service docker restart

For systems such as CentOS and RedHat, services are managed through systemd, and the configuration file path is /etc/systemd/system/docker.service.d/docker.conf. After updating the configuration, you need to manage the Docker service through the systemctl command:

sudo systemctl daemon-reload
sudo systemctl start docker.service

In addition, if the service is not working properly, you can determine the problem by viewing the log information of the Docker service. For example, the log file on the RedHat system may be /var/log/messages, and the command can be executed on the Ubuntu or CentOS system journalctl -u docker.service.
After restarting the Docker service each time, you can check the Docker information (docker info command) to ensure that the service is running normally.

Guess you like

Origin blog.csdn.net/weixin_44826356/article/details/109298445