0

I am running Cypress version 10.9 from inside Docker in a Mac OS. I set my base URL as localhost:80. As a simple example, I am running an Apache server on localhost:80 which if I go to a web browser, I get the 'It works!' page, so it is indeed up. I also can ping localhost:80 from the same terminal I am executing my Docker Cypress container.

But I get this error every time when attempting to run my Cypress container:

   Cypress could not verify that this server is running:

  > http://localhost

We are verifying this server because it has been configured as your baseUrl.

I do see there are some stackoverflow posts(ie, [https://stackoverflow.com/questions/53959995/cypress-could-not-verify-that-the-server-set-as-your-baseurl-is-running][1]) that talk about this error. However, the application under test in these posts are inside another Docker container. The Apache page is not under a container.

This is my docker-compose.yml:

version: '3'

services:
  # Docker entry point for the whole repo
  e2e:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      CYPRESS_BASE_URL: $CYPRESS_BASE_URL
      CYPRESS_USERNAME: $CYPRESS_USERNAME
      CYPRESS_PASSWORD: $CYPRESS_PASSWORD
    volumes:
      - ./:/e2e

I pass 'http://localhost' from my environment CYPRESS_BASE_URL setting.

This is the docker command I use to build my image:

docker compose up --build

And then to run the Cypress container:

docker compose run --rm e2e cypress run

Some other posts suggest running the docker run command with --network to make sure my Cypress container runs on the same network as the compose network(ref: Why Cypress is unable to determine if server is running?) but I am executing 'docker compose run' which does not have a --network argument.

I also verified that my /etc/hosts has an entry of 127.0.0.1 localhost as other posts have suggested. Any suggestions? Thanks.

ray805
  • 17
  • 5
  • It seems odd to compose a single service and have everything it needs to connect to _outside_ that network, what's the context here? You can look at the options in e.g. https://stackoverflow.com/q/24319662/3001761 but a different topology entirely might be a better solution. – jonrsharpe Oct 25 '22 at 21:43
  • Thank you for the link! Setting the url to host.docker.internal worked. As far as your question, we have an internal application we are testing against. If you can set your comment as an answer, I will try to award you points. – ray805 Nov 03 '22 at 20:05

0 Answers0