For a multi-container job, can we expose port of a container running in gitlab-runniner which is using docker-executor?
08:33 06 Jul 2026

Here is the scenario:

I'm trying to run a multi-container job, in such a way that one container can communicate with other.

For a gitlab-runner using docker-executer, I'm able to achieve the functionality using alias.

But when I'm trying to use localhost, it throws error (which is obvious as the two containers are running on same vm has their own separate network namespaces)

But while running containers manually on local, we can forward the ports. can we do the same in GitLab CI pipeline (using the docker-executor)

stages:
  - multi-container-job

communication-test:
  stage: multi-container-job

  image: curlimages/curl:latest

  services:
    - name: nginx:latest
      # alias: web

  script:
    - echo "Waiting for nginx..."
    - sleep 5

    # - echo "Trying alias..."
    # - curl http://web

    - echo "Trying localhost..."
    - curl http://localhost
gitlab continuous-integration gitlab-ci gitlab-ci-runner