【发布时间】:2020-09-03 22:35:34
【问题描述】:
这是我的 docker-compose.yml 我正在尝试在我的本地项目上运行 cypress,但它拒绝在端口上运行。 我做错了什么?
version: '3.2'
# run Cypress tests and exit with command
# docker-compose up --exit-code-from cypress
services:
cypress:
# the Docker image to use from https://github.com/cypress-io/cypress-docker-images
image: "cypress/included:5.0.0"
environment:
- CYPRESS_baseUrl=http://localhost:3000
# share the current folder as volume to avoid copying
working_dir: /e2e
command: "--browser chrome"
ports:
- 3333:3000
volumes:
- ./:/e2e
compose-docker 的结果:
cypress_1 |
cypress_1 | Cypress automatically waits until your server is accessible before running tests.
cypress_1 |
cypress_1 | We will try connecting to it 3 more times...
cypress_1 | We will try connecting to it 2 more times...
cypress_1 | We will try connecting to it 1 more time...
cypress_1 |
cypress_1 | Cypress failed to verify that your server is running.
cypress_1 |
cypress_1 | Please start this server and then run Cypress again.
e2e_cypress_1 exited with code 1
Aborting on container exit...
我确定我的 localhost:3000 正在运行,我可以通过浏览器运行它。
【问题讨论】:
-
被测系统是否在主机的 3000 端口上运行?如果是这样,那么我们需要在
CYPRESS_baseUrl中提供主机的docker-internal ip(docker-machine ip),而不是localhost。 -
docker在我的本地机器上,项目也在本地
-
再次:如果被测系统运行在docker主机上,而不是和cypress在同一个容器中,那么我们需要将
CYPRESS_baseUrl指向docker主机。 -
正确,测试根本不在容器中运行,cypress 是一个 docker 容器。如何为 cypress 容器定义 CYPRESS_baseUrl?
-
在您的撰写文件中。在
- CYPRESS_baseUrl=http://localhost:3000行中,将localhost更改为主机的docker-internal ip 地址。
标签: docker docker-compose cypress