Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect back to main container from GitlabCI service

Tags:

gitlab-ci

I am using Gitlab CI with docker executor and services.

During test I'm starting a server in the main script, and I need the service to make a request back to the main script.

Is there address/alias I can use to connect back to the main build script? Something like host.docker.internal.

Pseudo-example:

test:
  services:
    name: ping-pong-service
    variables:
      CALLBACK_ADDRESS: 'http://host.docker.internal:8090/pong'
  script:
  - "Start a server at 0.0.0.0:8090"
  - curl http://ping-pong-service:80/ping

Supose that ping-pong-service is a service that when receiving any http request on :80, performs new request to CALLBACK_ADDRESS. What should I enter into CALLBACK_ADDRESS to connect back to main container?

I tried looking into what containers get started on the runner, but the main container doesn't seem to have predictable name or alias in the docker network.


Env:

  • Docker: 20.10.12
  • Gitlab Runner: 14.8.0, self-hosted, FF_NETWORK_PER_BUILD=1
  • Gitlab: 14.9.2-ee, self-hosted
like image 869
michalhosna Avatar asked Oct 30 '25 03:10

michalhosna


1 Answers

When using the FF_NETWORK_PER_BUILD feature flag for networks per job, containers started using services: can reach the main job container using the network alias build

Assuming your service is configured as you describe, you would use:

variables:
  CALLBACK_ADDRESS: 'http://build:8090/pong'

Note: this does not apply to containers started using docker run in the job container for this scenario.

like image 57
sytech Avatar answered Nov 03 '25 00:11

sytech



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!