7 months ago (04-24)  Technology |   First to comment  16 
post score 0 times, average 0.0

Docker run Docker?

Docker technology is currently widely used in DevOps. We need to package the test or build code and automation scripts into Docker images and deploy them in various operating environments.In CI/CD, we use some CI/CD servers, such as Jenkins and GoCD, to build and deploy our applications to automate CI/CD.Now some CI/CD servers are also Dockerized on real physical machines.So we need to build (build) and run our Docker image inside the Docker container of the CI/CD server. This involves the "Docker run Docker" problem. A very natural idea is, do we need to install a Docker Daemon and Docker command in the CI/CD server image?However, running Docker in Docker always feels awkward. Extra installation and running of Docker undoubtedly increases the size of the CI/CD server image, and also increases the depth of Docker. In fact, we do not need to install Docker on the CI/CD server.Run our image on the CI/CD server with the following command:

Principle: Grafting

Docker adopts the C/S architecture. Docker's successful operation requires the support of Docker Daemon and Docker Client (client). When we run some commands such as docker build, we actually need Docker Client to connect to Docker Daemon to send commands. Docker Daemon will The host operating system allocates resources such as files and networks. Docker in Docker By default, the Docker daemon generates a socket (/var/run/docker.sock) file to communicate with the local process and does not listen on any ports, so you can only use the docker client locally or use the Docker API to operate .Under normal circumstances, our access to the local service often communicates via the IP address of the IP:port of 127.0.0.1:8080, and the sock file is a UNIX domain socket. It can pass through the file system ( Instead of a network address) a socket for addressing and access. From the perspective of appearance, the above command still seems to be in the "run docker inside Docker", in fact, this is a misunderstanding.Docker run provides the -v parameter to map host files to docker.For example, with -v /var/run/docker.sock:/var/run/docker.sock , we map the hosted Docker Daemon socket to the Docker Container; when the docker client inside the Container passes /var/run/docker When .sock went to operate the Docker Daemon, these operations were transferred to the host Docker Daemon.  

Extend: Operate remote host

Since the docker client communicates with the local Docker Daemon via a socket, we can naturally think that if we want to connect to a remote DockerDaemon via a socket on another host, is it possible to remotely manipulate the Docker host to build and run the image?The answer is yes, you need to let the Docker daemon listen on a port, in order to achieve remote communication, and the need to modify the docker client connection host is a remote address and not a local sock file.Since Docker C/S uses the Rest API as the communication protocol, this provides an extension for us to use a third-party client (such as postman) to operate docker and even develop the client itself.

 

This article has been printed on copyright and protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain authorization. If you feel that this article is useful to you, you can click The following "Sponsored Authors" rewarded the authors!

Included in Original Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/docker-in-docker-2.html

Post comment

Style

No Comment

登录

Forget password?

您也可以使用第三方帐号快捷登录

切换登录

注册

TW