Docker dind:无法连接到 Docker 守护进程

Docker dind : Cannot connect to the Docker daemon

虽然 运行 docker:dind 我不能使用 docker login 命令和任何其他 docker 命令。

我的用例是我有一个 Nexus Docker 注册表,我正在尝试通过 GitLab CI.

连接到这个注册表
docker run --rm -it docker:stable-dind docker login -u user -p password https://registry.mine.io

给予:

Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

只需在命令中添加 --privileged

docker run --rm -it --privileged docker:stable-dind docker login -u user -p password https://registry.mine.io

我在这篇文章中找到了相同问题的解决方案 https://www.santoshsrinivas.com/docker-on-ubuntu-16-04/

您需要 运行 使用您的 gitlab-ci worker

在机器上执行下一条命令
sudo groupadd docker
sudo gpasswd -a gitlab-runner docker
sudo service docker restart