我需要在docker容器中运行我的脚本
version: "3"
services:
chrome:
image: selenium/node-chrome:4.0.0-rc-1-prerelease-20210823
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "6900:5900"
selenium-hub:
image: selenium/hub:4.0.0-rc-1-prerelease-20210823
container_name: selenium-hub
ports:
- "4444:4444"
app:
build:
context: .
volumes:
- . :/home/saimon/
network_mode: "host"
depends_on:
- selenium-hub
- chrome
command:
python3 app.py
environment:
- SELENIUM_REMOTE_HOST=selenium-hub在我的应用程序I中:
driver = webdriver.Remote(command_executor='http://selenium-hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME, options=self.chrome_options)我制作:船坞-构图制作
sudo坞-编写运行--rm应用程序或坞-编写-f坞-复合. app向上
并显示此错误:
NewConnectionError('上的port=4444对象引起:未能建立新连接: Errno -3名称解析中的临时失败)
发布于 2021-08-23 19:02:39
如果您希望能够从应用程序容器连接到network_mode: "host",请删除http://selenium-hub:4444
还应该尝试使用env-var。
import os
host = os.environ['SELENIUM_REMOTE_HOST']
driver = webdriver.Remote(command_executor='http://{}:4444/wd/hub'.format(host),
...https://stackoverflow.com/questions/68897526
复制相似问题