GitLab CI runner can't connect to tcp://localhost:2375 in kubernetes

报错的.gitlab-ci.yml配置如下

image: docker:latest
services:
  - docker:dind
variables:
  DOCKER_HOST: tcp://localhost:2375
stages:
  - package
package:
  stage: package
  script:   
    - docker login -u "admin" -p "Harbor12345" 192.168.1.100
    - docker build -t 192.168.1.100/development/example-nodepm2:0.1 .
    - docker push 192.168.1.100/development/example-nodepm2:0.1
    - docker rmi 192.168.1.100/development/example-nodepm2:0.1

  

报错:Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
ERROR: Job failed: command terminated with exit code 1

环境:harbor+gitlab ci runner+kubernetes 构建ci/cd流程

Dockerfile 

FROM keymetrics/pm2:latest-alpine

# Bundle APP files
RUN mkdir -p /home/Service
WORKDIR /home/Service
COPY . /home/Service
#COPY src src/
#COPY package.json .
#COPY pm2.json .

# Install app dependencies
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install --production

# Show current folder structure in logs
#RUN ls -al -R
EXPOSE 3000
CMD [ "pm2-docker", "start", "pm2.json" ]

  

可用的.gitlab-ci.yml配置如下(主要原因是因为services服务使用的docker版本问题

image: docker:stable
services:
  - name: docker:18.09-dind
    command: ["--insecure-registry=192.168.1.100"]

variables:
  DOCKER_HOST: tcp://localhost:2375
  DOCKER_DRIVER: overlay2

before_script:
  - docker search node # just to test
  - docker info # just to test

build:
  stage: build
  script:
    - docker login -u "admin" -p "Harbor12345" 192.168.1.100
    - docker build -t 192.168.1.100/development/example-nodepm2:0.1 .
    - docker push 192.168.1.100/development/example-nodepm2:0.1
    - docker rmi 192.168.1.100/development/example-nodepm2:0.1
--insecure-registry参数解决harbor走http协议问题,如配置了https则不需要传command参数


 

参考:https://stackoverflow.com/questions/55065490/gitlab-ci-runner-cant-connect-to-tcp-localhost2375-in-kubernetes

https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-the-overlayfs-driver

 

posted @ 2019-07-31 11:15  也曾少年  阅读(1536)  评论(0编辑  收藏  举报