3

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```
sqr
  • 365
  • 2
  • 12
  • 29

1 Answers1

1

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
sytech
  • 29,298
  • 3
  • 45
  • 86
  • thank you, @sytech, i will try out and update. – sqr Nov 04 '21 at 02:41
  • this doesn't seem to work in my testing. 'docker:8000' gives me connection refused. i have also tried assigning an alias to dind, and curl $alias:8000; it also refused. – sqr Nov 05 '21 at 08:30
  • @sqr ah, I see you have the `FF_NETWORK_PER_BUILD` feature flag enabled. In which case, this won't work. You should remove that feature flag for this to work. – sytech Nov 05 '21 at 17:06
  • thanks, I just tried that and it refused connection again. – sqr Nov 07 '21 at 01:26
  • I updated the post with my latest yaml. – sqr Nov 07 '21 at 01:26
  • Are you sure you're using the right ports for the container @sqr ? This works for me using `docker run --rm -d -it -p 8000:80 strm/helloworld-http`. Are you using gitlab.com or self-hosted runners? – sytech Nov 07 '21 at 02:33
  • I am using shared runner. It seems the image I randomly choose actually made a difference here. I could reach port 8000 using your provided image. Thank you for the patient help! I marked yours as the correct answer. – sqr Nov 07 '21 at 08:13