简体   繁体   中英

alpine cannot access docker daemon when using gitlab-ci

I have a custom gitlab ci that I want to compile a Golang app and build a docker image. I have decided to use alpine docker image for the gitlab runner. I can't seam to get docker started. I have tried to manually start docker and get an error ( * WARNING: docker is already starting ) and if I don't manually start the docker service I get ( Fails (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ) Any one else experience this?

This would not be a duplicate question. Gitlab runner runs the docker alpine container in root (verified by running whoami). For the sake of trying I did try usermod -aG docker $(whoami) and had the same output.

.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?)

By default you cannot use Docker-in-docker. You should configure your runner like this . Then, as stated in the explanation also use docker:latest as image instead of alpine .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM