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

 

转载于:https://www.cnblogs.com/caidingyu/p/11275058.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值