How to perform web requests against a container in Gitlab CI

In my build pipeline I want to perform a simple smoke test of my system by running the docker container I just built and calls its Ping method. However, in the CI environment I cannot access the running container using localhost and I have no idea how else to proceed.

    - docker build -t myregistry/mycontainer .
 # Smoke test 
    - docker run -d --rm -p 5000:5000 myregistry/mycontainer:latest 
    - curl --fail --connect-timeout 5 --max-time 10 --retry 25 --retry-delay 5 --retry-max-time 200 --retry-connrefused "localhost:5000/status/ping" 

It just responds with connection refused. The container starts no problem, as is visible when running the container without -d --rm, so I’m guessing it’s because localhost is not available to access the container.

There’s several options:

  1. include "–network=host " option so the docker container network will be be accessible
  2. Specify docker container ip address (e.g.
  3. Setup a docker network. (e.g. docker network create gitlab-network)

I tried the first option but that did not work. How would I get the container ip address within the virtual docker network?

I guess I’ll have to look into the last option when I get the time. I haven’t worked with custom network before.

Did you ever get this working. I am stumped as well.

@hozawa Can you give me some pointers on how to try option 2 and 3 please?

No, I ended up abandoning the idea - though I would still be interested in a solution.

1 Like