Background:
When writing CI, the image is declared as the execution environment of the job, and each job is executed in a pure container.
Sometimes, we need a docker container environment to perform docker build, docker push and other operations. Looking at the official docker image, we find that there are two main versions: docker:latest, docker:dind and docker:git.
(Recommended tutorial: docker tutorial)
docker:dind
This image contains Docker client (command line tool) and Docker daemon.
Through the docker history docker:dind command, we found that docker:dind installed Docker daemon on the basis of docker:latest, and the last two build commands are:
IMAGE CREATED CREATED BY SIZE COMMENT 66dc2d45749a 8 weeks ago /bin/sh -c #(nop) CMD [] 0B <missing> 8 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["dockerd-entr… 0B ...
In run the image When, the sh CMD parameter cannot be specified. The dockerd-entrypoint.sh command will not start the Docker daemon when receiving this parameter. To correctly start the Docker daemon in the container and enter the container, you need to proceed step by step:
$ docker run -d --name dind --privileged docker:dind # 启动容器 $ docker logs -f dind # 查看启动日志 $ docker exec -it dind sh # 进入容器
When starting the docker:dind container, the parameter --privileged must be added, otherwise the Docker daemon will report an error when starting.
docker:latest
This image only contains the Docker client and requires Docker daemon support. You can use docker:dind or mount the host's /var/run/docker. sock.
The --privileged parameter is not required to start this image.
Through the docker history docker:latest command, the CMD default is sh:
81f5749c9058 3 months ago /bin/sh -c #(nop) CMD ["sh"] 0B <missing> 3 months ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry… 0B ...
Startup method one: Mount the host sock file
$ docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest
Startup method two: Cooperate with docker: dind
Put docker:dind and docker:latest into the same network, and specify the alias of the dind container in the network as docker, because the default daemon host in the latest container is called docker.
In addition, you need to pay attention to the certificate issue. The new version of Docker client requires a TLS certificate to communicate with the Docker daemon to ensure communication security. The docker:dind container will generate the certificate to the directory specified by the environment variable DOCKER_TLS_CERTDIR. The certificate needs to be mounted and provided. For use by docker:latest containers.
$ docker run --privileged --name some-docker -d \ --network some-network --network-alias docker \ -e DOCKER_TLS_CERTDIR=/certs \ -v some-docker-certs-ca:/certs/ca \ -v some-docker-certs-client:/certs/client \ docker:dind $ docker run --rm --network some-network \ -e DOCKER_TLS_CERTDIR=/certs \ -v some-docker-certs-client:/certs/client:ro \ docker:latest
docker:git
docker:git is docker:latest that contains the git command, which is convenient for using Git in CI.
The above is the detailed content of What is the difference between docker:latest and docker:dind. For more information, please follow other related articles on the PHP Chinese website!

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

The methods to view Docker logs include: using the docker logs command, for example: docker logs CONTAINER_NAME Use the docker exec command to run /bin/sh and view the log file, for example: docker exec -it CONTAINER_NAME /bin/sh ; cat /var/log/CONTAINER_NAME.log Use the docker-compose logs command of Docker Compose, for example: docker-compose -f docker-com

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Four ways to exit Docker container: Use Ctrl D in the container terminal Enter exit command in the container terminal Use docker stop <container_name> Command Use docker kill <container_name> command in the host terminal (force exit)

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

How to restart the Docker container: get the container ID (docker ps); stop the container (docker stop <container_id>); start the container (docker start <container_id>); verify that the restart is successful (docker ps). Other methods: Docker Compose (docker-compose restart) or Docker API (see Docker documentation).


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software