[英]Output from Python running on Docker back to host with docker-compose
[英]running python selenium in docker-compose
我正在尝试在docker-compose中运行python selenium。 我有以下文件:
泊坞窗,compose.yml:
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
depends_on:
- chrome
ports:
- '8443:8443'
chrome:
image: selenium/node-chrome:3.14.0-gallium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
hub:
image: selenium/hub:3.14.0-gallium
ports:
- "4444:4444"
Dockerfile:
FROM python:latest
COPY test.py /code/test.py
WORKDIR /code
RUN pip install --upgrade pip
RUN pip install pytest
RUN pip install pytest-asyncio
RUN pip install selenium
test.py:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor='http://hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
)
print(driver)
我跑:
docker-compose build
docker-compose run python test.py
当我尝试创建webdriver时,在test.py中出现了拒绝连接的错误。
'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffb3b34d550>: Failed to establish a new connection: [Errno 111] Connection refused')'
查看日志,发现集线器和chrome驱动程序已启动并正在运行,并且chrome驱动程序已连接到集线器。 我可以从应用程序ping集线器和Chrome容器。 有任何想法吗?
这是一个工作版本:在测试之前,还请确保等待集线器准备好链接准备就绪: https : //github.com/SeleniumHQ/docker-selenium#waiting-for-the-grid-to-ready
version: "3.6"
services:
selenium-hub:
restart: always
image: selenium/hub:3.14.0
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
restart: always
image: selenium/node-chrome-debug:3.14.0
ports:
- "5900-5999:5900"
depends_on:
- selenium-hub
environment:
HUB_HOST: selenium-hub
HUB_PORT_4444_TCP_ADDR: selenium-hub
HUB_PORT_4444_TCP_PORT: 4444
DBUS_SESSION_BUS_ADDRESS: "/dev/null"
links:
- selenium-hub:hub
我有一个非常相似的设置,我唯一能看到的区别是您没有在chrome实例下给出HUB_PORT arg:
environment:
HUB_HOST: hub
HUB_PORT: 4444
我用来设置的示例在这里: SeleniumHQ / docker-selenium
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.