gpt4 book ai didi

docker - Docker拒绝在我的本地主机:3000 port上工作

转载 作者:行者123 更新时间:2023-12-02 17:51:57 25 4
gpt4 key购买 nike

这是我的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...
我知道我的本地主机:3000正在运行,我可以通过浏览器运行它。

最佳答案

问题在于该容器不知道您的localhost主机名,因为它在隔离的docker网络中运行。如果您想让容器知道您的本地网络,则必须Use host networking并且容器的网络堆栈未与Docker主机隔离。

    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"
network_mode: "host"
ports:
- 3333:3000
volumes:
- ./:/e2e

关于docker - Docker拒绝在我的本地主机:3000 port上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63732523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com