sqr
sqr

Reputation: 427

problem connecting to docker container from gitlab-runner container

I am trying to create a gitlab pipeline and run some containerized test in the runner; with DinD service, the container seems to be up and running, but I couldn't connect to it from the runner?

is there any addtional settingg required? thanks!

image: docker:19.03.13

stages:
  - scan

RUN:
  stage: scan
  services:
    - name: docker:dind
      command: ["--tls=false"]
  before_script:
    - docker info
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_TLS_CERTDIR: ""
    DOCKER_DRIVER: overlay2

  script:
    - |
    - apk add curl
    - apk add --no-cache --upgrade bash
    - docker run -d -p 8000:8000 jdkelley/simple-http-server
    - docker network ls
    - curl docker:8000

what i get:

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
abd87e7148db        bridge              bridge              local
d88e547f3e91        host                host                local
2f6727a12c9c        none                null                local

$ curl docker:8000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to docker port 8000 after 7 ms: Connection refused```

Upvotes: 3

Views: 773

Answers (1)

sytech
sytech

Reputation: 40891

When you use the docker:dind your services are not available on localhost -- they are available at the alias of the docker daemon -- the docker:dind service. So use the container alias to reach the container. In this case, it's docker

    - docker run -d -p 8000:8000 jdkelley/simple-http-server
    - curl docker:8000

Upvotes: 2

Related Questions