Failed to connect to Localhost port 80: Codeception

Hello there.

I’m trying to set up a simple acceptance test using codeception (PHP) and gitlab. All the test does is visit the homepage of my app and confirm the existence of some text. It doesn’t rely on Selenium or anything, it just uses the Guzzle library which under the hood uses curl. The test works fine when I run it from inside the container on my local machine.

However, when it runs via CI

I get a cURL error saying: “Failed to connect to localhost port 80: Connection Refused”. This leads me to believe that the command is not being run from inside the container but rather from the virtual machine that the runner is running from.

This is the step being run:

tests:
  stage: test
  script:
    - ./vendor/bin/codecept run --steps
  only:
    - /^feature\/.+/

How can I get the tests to run from inside the container? If not possible, how can I run them successfully from outside the container. Something like ‘docker exec <command’. Problem with the second solution is 1 docker is not installed and 2 I don’t know the container name.

So I figured out the reason… apache was not started. Even though it starts automatically locally via docker-compose up -d. Anyone know the reason for that?

So I had to do two things. First was to put apachectl start in my before_scripts section. Second was to add an environment variable for APACHE_DOCUMENT_ROOT because it is a different path in gitlab ci than my local build.

Hope that helps someone.