Docker error during connect: Post http://docker:2375/v1.40/build?

早过忘川 提交于 2021-01-29 09:41:51

问题


I am using docker+machine to run my gitlab ci/cd jobs.

So my .gitlab-ci.yml looks like below:

stages:
  - RUN_TESTS

image:
  name: docker:stable

services:
  - name: docker:dind

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""    

build-docker:
  stage: RUN_TESTS
  script:
    - echo "Running the tests..."
    - docker build -t run-tests .

This works totally fine with docker:dind image set as the service block as shown above.

Now here comes the fun part, I need some other packages inside the docker:dind image. So I wrote the Dockerfile as below:

FROM docker:dind

RUN apk update

ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

RUN apk add groff
RUN pip3 install awscli
RUN apk --purge -v del py-pip
RUN rm /var/cache/apk/*

So, I built the above image and pushed it into my dockerhub.

As of now, everything is cool. Image built successfully and pushed successfully.

And then I changed the services in the .gitlab-ci.yml to my new images as below:


services:
  - name: 199508/dind-new:latest

And I ran the pipeline and I get the error below.

This error I am getting below is strange:

error during connect: Post http://docker:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=n6fvaaoisom3ny2cfozrlom50&shmsize=0&t=run-tests&target=&ulimits=null&version=1: dial tcp: lookup docker on : no such host

The only change I did was installing some applications/dependencies in the above Dockerfile but why it is not working? How come when I use docker:dind it is working and when I created a new Dockerfile with the same docker:dind base image and it doesn't work?

Can someone please help me?


回答1:


Actually I just run into this problem yesterday The main thing is to switch to docker image version In Your case in the Dockerfile not like here

FROM docker:18.09

And change the port: The lines commented out are the once the didn't work for me.

image: 199508/dind-new:v5
services:
  # - docker:19.03.12-dind
  - docker:18.09-dind


variables:
  # Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
  DOCKER_HOST: tcp://docker:2375/
  # DOCKER_HOST: tcp://docker:2376
  # DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_TLS_CERTDIR: ""
  CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
  DOCKER_DRIVER: overlay2


来源:https://stackoverflow.com/questions/65842641/docker-error-during-connect-post-http-docker2375-v1-40-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!