无法在gitlab-ci Runner上运行最新的docker [英] can not run docker latest on gitlab-ci runner
问题描述
我正在测试gitlab-ci并尝试从Dockerfile在注册表上生成映像。
I'm testing gitlab-ci and trying to generate an image on the registry from the Dockerfile.
我有相同的代码可以测试:
I have the same code just to test:
#gitlab-ci
image: docker:latest
tages:
- build
- deploy
build_application:
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . -f Dockerfile
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-test
输出:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker正在运行映像正在被拉出,但我无法执行docker命令。
docker is running the image is being pulled but I can not execute docker commands.
在我的本地环境中运行:
In my local environment if a run:
docker run -it docker:latest
我留在容器内并运行docker info我也有同样的问题。我必须通过以这种方式运行容器来修复它:
I stay inside the container and run docker info i have the same problem. I had to fix it by running the container on this way:
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest
但我不知道如何在gitlab-ci上修复它。我将跑步者配置为:
but I do not know how to fix it on gitlab-ci. I configured my runner so:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
也许有人可以向正确的方向发展。
谢谢
Maybe someone can put me in the right direction. thanks
推荐答案
通过默认无法运行docker-in-docker(DIND)(作为安全措施)。
By default it is not possible to run docker-in-docker (DIND) (as a security measure).
本节是您的解决方案。您必须使用Docker-in-Docker。
This section in the Gitlab docs is your solution. You must use Docker-in-Docker.
在配置运行程序以使用DIND后,您的 .gitlab-ci.yml
如下所示:
After configuring your runner to use DIND your .gitlab-ci.yml
will look like this:
#gitlab-ci
image: docker:latest
variables:
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
- docker info
stages:
- build
- deploy
build_application:
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . -f Dockerfile
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-test
这篇关于无法在gitlab-ci Runner上运行最新的docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!