cypress-io/cypress-example-docker-compose

cypress could not verify this server was running

heaversm opened this issue · 1 comments

Hi - attempting to adapt this example to my own environment, which very closely mirrors this codebase, but getting a:

cypress      | Cypress could not verify that this server is running:
cypress      | 
cypress      |   > http://client
cypress      | 
cypress      | We are verifying this server because it has been configured as your baseUrl.
cypress      | 
cypress      | Cypress automatically waits until your server is accessible before running tests.
cypress      | 
cypress      | We will try connecting to it 3 more times...
cypress      | We will try connecting to it 2 more times...
cypress      | We will try connecting to it 1 more time...
cypress      | 
cypress      | Cypress failed to verify that your server is running.
cypress      | 
cypress      | Please start this server and then run Cypress again.

given this docker-compose.yml in the root:

client:
    image: graceland/client_dev
    networks:
      - allhosts
    volumes:
      # this is where our code is mounted into the running container
      - ./client/:/client
      - ./shared/:/client/src/shared-copied # see shared-copied.md
    working_dir: /client
    command: yarn start
    environment:
      PORT: 3000
    ports:
      - "3000:3000"
e2e:
    #image: "cypress/included:10.6.0"
    image: "cypress"
    build: ./e2e
    container_name: cypress
    depends_on:
      - client
    environment:
      - CYPRESS_baseUrl=http://client
    command: ["./wait-for-it.sh", "-t","30","http://localhost:3000", "--", "npx","cypress","run"]

    volumes:
      - ./e2e/cypress:/app/cypress
      - ./e2e/cypress.config.js:/app/cypress.config.js
      - ./e2e/wait-for-it.sh:/app/wait-for-it.sh

and this cypress.config.js in the /e2e folder:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    baseUrl: "http://localhost:3000",
    supportFile: false,
  },
});

any idea what's going on here? Running this on my local machine with docker-compose up - and I can see http://localhost:3000 in my browser.

Adding the networks object on both services may help you to fix that issue.
This is an example from a project that worked for me:

version: "3.2"

networks:
  some_network:
services:
  frontend:
    container_name: frontend
    build:
      context: ./build/frontend
      dockerfile: Dockerfile
    volumes:
      - ./front:/usr/src/app
    ports:
      - 3000:3000
    networks:
      - some_network
  e2e:
    image: cypress/included:4.1.0
    container_name: e2e
    depends_on:
      - frontend
    environment:
      - CYPRESS_baseUrl=${CYPRESS_BASEURL}
    working_dir: /e2e
    command: ["./wait-for-it.sh", "-t","200","${CYPRESS_BASEURL}", "--", "npx","cypress","run"]
    volumes:
      - ./e2e/cypress:/app/cypress
      - ./e2e/cypress.config.js:/app/cypress.config.js
    networks:
      - some_network

where $CYPRESS_BASEURL is the docker service (http://frontend:3000)