Docker in Docker: /var/run/docker.sock

Docker containers in which docker run/ docker build?

Docker container technology is currently serving micro / continuous integration / sustained delivery of the first selection field. In DevOps, we need a variety of back-end / front-end test / build environment Docker packaged into a mirror, and then when needed, Jenkins will use these images to start the task container to perform Jenkins.

For easy maintenance, our CI system, such as Jenkins, will be deployed using Docker way.
Jenkins tasks Some tasks need to build micro-Docker service into a mirror, and then pushed to the Harbor private warehouse.
Or all of the images and we Jenkins Master Jenkins Slave mirroring itself does not contain any additional build environment, you need to boot image contains the corresponding environment when performing tasks to perform tasks.

We Jenkins Master, Jenkins Slaves are run inside the container, how to call them inside docker runthe command boot image contains a CI environment it?
In these CI mirror inside, we compiled from the source code, and how docker buildto compile the results Docker packaged into a mirror, and then pushed to the network warehouse it?

The answer revealed below.

/var/run/docker.sock

Docker adopted a Client / Server architecture, we used the docker xxxcommand tool, just docker's client, when we execute the command line, the engine actually communicate with the client docker by this command.

When we install docker-ce through apt / yum, will automatically generate a systemd of service, so after the installation is complete, the need sudo systemctl enable docker.serviceto enable the service.
The Docker service starts, is the docker engine, to see /usr/lib/systemd/system/docker.service, to see such a statement:

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

By default, Docker daemon will generate a socket ( /var/run/docker.sock) file for local interprocess communication, and therefore can only be used docker client at the local end or the use of Docker API to operate.
UNIX domain socket file is a sock, it can be addressed and accessed via the file system (instead of the network address).

If we installed inside the container docker client, and by adding parameters -v /var/run/docker.sock:/var/run/docker.sockwill host the /var/run/docker.sockfile to mount the volume into the container, so that we can achieve "Docker in Docker", use the command docker in the container.

Remember, the real implementation of our docker command is docker engine, and the engine running on the host. So this is not really a "Docker in Docker".

practice

Mirrored in the package docker-cli Dockerfile fragment:

ENV DOCKER_VER=18.09.7

RUN curl -fSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VER}.tgz \
  && tar xzvf docker-${DOCKER_VER}.tgz --strip 1 \
                 -C /usr/local/bin docker/docker \
  && rm docker-${DOCKER_VER}.tgz

reference

Guess you like

Origin www.cnblogs.com/kirito-c/p/11357522.html