Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GItLab CI gives curl: (7) Failed to connect to localhost port 8090: Connection refused

The issue is I get the curl: (7) Failed to connect to localhost port 8090: Connection refused GItLab CI error but this does not happen on my laptop where I get the source html of the webpage. The .gitlab-ci.yml below is a simple reproduction of the issue. I have spent numerous hours trying to figure this out - i'm sure someone else has also.

GitLab Docker Runner Verbose

Aside: This isn't a similar question - since they don't offer a solution.

GitLab Repo: https://gitlab.com/mudassir-ahmed/wordpress-testing-with-gitlab-ci/tree/another-approach but the only file it contains is the .gitlab-ci.yml shown below...

image: docker:stable

variables:
  # When using dind service we need to instruct docker, to talk with the
  # daemon started inside of the service. The daemon is available with
  # a network connection instead of the default /var/run/docker.sock socket.
  #
  # The 'docker' hostname is the alias of the service container as described at
  # https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services
  #
  # Note that if you're using the Kubernetes executor, the variable should be set to
  # tcp://localhost:2375/ because of how the Kubernetes executor connects services
  # to the job container
  # DOCKER_HOST: tcp://localhost:2375/
  #
  # For non-Kubernetes executors, we use tcp://docker:2375/
  DOCKER_HOST: tcp://docker:2375/
  # When using dind, it's wise to use the overlayfs driver for
  # improved performance.
  DOCKER_DRIVER: overlay2

services:
  - docker:dind

before_script:
  - docker info

build:
  stage: build
  script:
    - apk update
    - apk add curl
    #- hostname -i
    - docker container ls
    - docker run -d -p 8090:80 --name nginx-server kitematic/hello-world-nginx
    - curl localhost:8090 # This works on my laptop but not on a GitLab runner.

like image 374
Mudassir Avatar asked Nov 18 '25 14:11

Mudassir


1 Answers

Referring to the answer from here : gitlab-ci.yml & docker-in-docker (dind) & curl returns connection refused on shared runner

There are two ways to fix this :

Option 1: Replace localhost in curl localhost:8090 with docker like this curl docker:8090

Option 2:

services:
  - name: docker:dind
    alias: localhost
like image 149
Blackout Avatar answered Nov 21 '25 22:11

Blackout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!