Skip to content

GitLab CI: localhost connection refused when using curl on running application

Using Gitlab CI, I am running a java application as a daemon which is a basic web service running in an embedded tomcat container on localhost:8080. The command to run the web service is as follows java -jar target/webservice-0.0.1-SNAPSHOT.jar & and the service is running as expected see output from ps -ef:

$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 21:58 ?        00:00:00 /bin/bash
root         9     1  0 21:58 ?        00:00:00 /bin/bash
root       167     9  0 21:59 ?        00:00:00 java -jar app/target/webservice-0.0.1-SNAPSHOT.jar
root       172     9  0 21:59 ?        00:00:00 ps -ef

The eventually tests will use this local web service running locally on the CI box.

The issue is the fact I cannot connect to localhost:8080 which the service is running on. The following is the behaviour:

$ curl -I http://127.0.0.1:8080/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

I have also tried several addresses to refer to localhost:

Does Gitlab CI not support access to localhost?

Below is my simple .yml to test the connection:

image: maven:3.3.9-jdk-8

test:
  script:
    - mvn -f app/pom.xml clean compile
    - mvn -f app/pom.xml package
    - ps -ef
    - java -jar app/target/webservice-0.0.1-SNAPSHOT.jar &
    - ps -ef
    - curl -I http://127.0.0.1:8080/