使用 gitlab 时 alpine 无法访问 docker 守护进程-ci
alpine cannot access docker daemon when using gitlab-ci
我有一个自定义的 gitlab ci,我想编译一个 Golang 应用程序并构建一个 docker 图像。我已经ci决定为 gitlab runner 使用 alpine docker 图像。我无法接缝 docker 开始。我曾尝试手动启动 docker 并出现错误 (* WARNING: docker is already starting
),如果我不手动启动 docker 服务,我会得到 (Fails (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
) 任何其他人的经验这个?
这不是一个重复的问题。 Gitlab runner 在 root 中运行 docker alpine 容器(由 运行 whoami 验证)。为了尝试,我确实尝试了 usermod -aG docker $(whoami)
并得到了相同的输出。
.gitlab-ci.yml
image: alpine
variables:
GO_PROJECT: linkscout
before_script:
- apk add --update go git libc-dev docker openrc
- mkdir -p ~/go/src/${GO_PROJECT}
- cp -r ${CI_PROJECT_DIR}/* ~/go/src/${GO_PROJECT}/
- cd ~/go/src/${GO_PROJECT}
- service docker start # * WARNING: docker is already starting
stages:
- compile
- build
compile:
stage: compile
script:
- go get
- go build -a
build:
stage: build
script:
- docker version # If I don't run (service docker start) I get this message: Fails (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?)
默认情况下您不能使用 Docker-in-docker。你应该configure your runner like this。然后,如解释中所述,还使用 docker:latest
作为图像而不是 alpine
.
我有一个自定义的 gitlab ci,我想编译一个 Golang 应用程序并构建一个 docker 图像。我已经ci决定为 gitlab runner 使用 alpine docker 图像。我无法接缝 docker 开始。我曾尝试手动启动 docker 并出现错误 (* WARNING: docker is already starting
),如果我不手动启动 docker 服务,我会得到 (Fails (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
) 任何其他人的经验这个?
这不是一个重复的问题。 Gitlab runner 在 root 中运行 docker alpine 容器(由 运行 whoami 验证)。为了尝试,我确实尝试了 usermod -aG docker $(whoami)
并得到了相同的输出。
.gitlab-ci.yml
image: alpine
variables:
GO_PROJECT: linkscout
before_script:
- apk add --update go git libc-dev docker openrc
- mkdir -p ~/go/src/${GO_PROJECT}
- cp -r ${CI_PROJECT_DIR}/* ~/go/src/${GO_PROJECT}/
- cd ~/go/src/${GO_PROJECT}
- service docker start # * WARNING: docker is already starting
stages:
- compile
- build
compile:
stage: compile
script:
- go get
- go build -a
build:
stage: build
script:
- docker version # If I don't run (service docker start) I get this message: Fails (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?)
默认情况下您不能使用 Docker-in-docker。你应该configure your runner like this。然后,如解释中所述,还使用 docker:latest
作为图像而不是 alpine
.