在我的 GitLab CI 管道中,我有一项工作使用 pytest 和 docker-compose 的组合来测试我的代码(我的 pytest 装置运行 docker-compose)。所以,我有类似的东西
test job:
image: ubuntu:20.04
services:
- docker:dind
script:
- apt -y update
- apt -y install python3-pip docker-compose
- ...
但是,当我尝试运行各种 Docker 命令时,我得到了
无法连接到位于 unix:///var/run/docker.sock 的 Docker 守护进程。 docker 守护进程是否正在运行?
如何连接到插座?当我从
ubuntu:20.04
切换到 docker:latest
时,它就起作用了。但是,我无法访问任何 Debian 软件包。
# When you use the dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket. Docker 19.03 does this automatically
# by setting the DOCKER_HOST in
# https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
其他容器无需手动设置。自行设置
DOCKER_HOST
。
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: "/certs"