When running Cypress tests in a Docker container, especially when using a local development environment like Laravel Herd, you might encounter issues with the container not being able to resolve or access the host's network. Here are a few steps you can take to resolve this issue:
-
Network Access: Ensure that the Docker container can access the host network. You can use the
--networkflag to connect the container to the host network. This allows the container to access services running on the host machine.Modify your Docker command to include the
--network hostoption:docker run -it --network host -v $(pwd):/e2e -w /e2e cypress/included:13.15.1Note: The
--network hostoption is available on Linux. If you're using macOS or Windows, Docker's networking works differently, and you might need to usehost.docker.internalto access the host machine. -
Use
host.docker.internal: If you're on macOS or Windows, you can change thebaseUrlin yourcypress.config.jsto usehost.docker.internal, which is a special DNS name that resolves to the host machine.Update your
cypress.config.js:import { defineConfig } from "cypress"; export default defineConfig({ e2e: { baseUrl: 'https://host.docker.internal', setupNodeEvents(on, config) { // implement node event listeners here }, }, }); -
Verify SSL: If your server uses HTTPS, ensure that the SSL certificate is trusted by the Docker container. You might need to disable SSL verification in Cypress for local development:
Add the following to your
cypress.config.js:import { defineConfig } from "cypress"; export default defineConfig({ e2e: { baseUrl: 'https://host.docker.internal', setupNodeEvents(on, config) { // implement node event listeners here }, // Disable SSL verification for local development chromeWebSecurity: false, }, }); -
Check Server Status: Ensure that your Laravel server is running and accessible from the host machine. You can test this by opening a browser and navigating to
https://auth-server.testorhttps://host.docker.internalto verify that the server is up and running.
By following these steps, you should be able to resolve the issue of Cypress failing to verify that your server is running when using Docker with Laravel Herd.