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

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, many CI/CD servers are actually made into a Docker Image running on a real physical machine. At this time, we actually need to build and run our CI/CD server's Docker container. Docker image, which 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? This is a very natural idea, but I always feel that installing Docker in the Docker image is a bit lame. In fact, we do not need to install Docker on the CI/CD server. Instead, we directly borrow from the host machine. So, we need to start "Docker in Docker" like this:

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. 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. Mount Volume with -v /var/run/docker.sock:/var/run/docker.sock We map Docker Daemon sockets from Docker to outer Docker sockets, passing -v $(which docker):/usr /bin/docker Mount Volume We map the docker docker command to the outer Docker docker command. In this way, the docker operation executed inside the Docker Container actually runs on the host machine. Docker in Docker Since Docker uses the Rest API to operate, if you want to operate the Docker host on another host, you need to let the Docker daemon listen on a port so that remote communication can be achieved.

 

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>>http://wangbaiyuan.cn/en/docker-in-docker-2.html

Post comment

Style

No Comment

登录

Forget password?

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

切换登录

注册

TW