I'm trying to run Cypress tests from Docker container with this in the Dockerfile:
FROM cypress/included:4.8.0
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY cypress.json /usr/src/app/cypress.json
I spin all my containers with docker-compose up -d --build
and they're running just fine but when
I try to run basic Cypress test with:
docker run -it -v $PWD:/services/cypress -w /usr/src/app --entrypoint=cypress tdd_cypress run
I get:
Cypress could not verify that this server is running:
> http://nginx:80
We are verifying this server because it has been configured as your `baseUrl`.
Cypress automatically waits until your server is accessible before running tests.
We will try connecting to it 3 more times...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...
Cypress failed to verify that your server is running.
Please start this server and then run Cypress again.
Here's my docker-compose file:
version: '3.7'
services:
users:
container_name: flask
build:
context: ./services/users
dockerfile: Dockerfile
volumes:
- './services/users:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test
- SECRET_KEY=python_rocks
depends_on:
- users-db
users-db:
container_name: postgres
build:
context: ./services/users/project/db
dockerfile: Dockerfile
ports:
- 5436:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
client:
container_name: react
build:
context: ./services/client
dockerfile: Dockerfile
volumes:
- './services/client:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 3007:3000
environment:
- NODE_ENV=development
- REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL}
depends_on:
- users
nginx:
container_name: nginx
build:
context: ./services/nginx
dockerfile: Dockerfile
restart: always
ports:
- 80:80
depends_on:
- users
- client
cypress:
container_name: cypress
build:
context: ./services/cypress
dockerfile: Dockerfile
depends_on:
- nginx
- users
- client
I found very similar topic here and the solution is pretty much the same like the one below but my Cypress instance keeps timing out.
UPDATE:
After receiving feedback from others I edited Cypress service within Docker-Compose to make it look like this:
cypress:
container_name: cypress
ipc: host
network_mode: host
build:
context: ./services/cypress
dockerfile: Dockerfile
and baseUrl
is set to http://nginx:80
and also tried http://client:3007
. Sadly, either way it had no effect on the error. I've ran docker-compose up -d --build
to ensure changes take effect.
Is there any good reason for Cypress not being able to access the Nginx on the port 80 ? Any feedback much appreciated.
localhost
, so Cypress is trying to connect to itself. Networking in Compose describes the overall network environment your containers will see and how to connect from one container to another. – David Maze