Хочу запускать скрипт на питоне через докер, если запускаю скрипт напрямую - все работает, если запускаю через docker-compose up
- получаю ошибку:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0',
port=4444): Max retries exceeded with url: /wd/hub/session (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f71bec86950>:
Failed to establish a new connection: [Errno 111] Connection refused'))
Сам скрипт на питоне (просто открыть страницу гугла и сделать скрин):
from selenium import webdriver
import time
capabilities = {
"browserName": "chrome",
"version": "83.0",
"platform": "LINUX",
}
driver = webdriver.Remote(
command_executor="http://0.0.0.0:4444/wd/hub",
desired_capabilities=capabilities
)
if __name__ == "__main__":
driver.get("https://google.com")
time.sleep(3)
driver.save_screenshot("test.png")
print("Success!")
Dockerfile
FROM python:3.7-alpine
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
docker-compose.yml
version: '3'
services:
selenoid:
image: aerokube/selenoid:latest-release
network_mode: bridge
ports:
- "4444:4444"
volumes:
- "./:/etc/selenoid/"
- "/var/run/docker.sock:/var/run/docker.sock"
command: ["-conf", "/etc/selenoid/browsers.json"]
app:
build: ./
command: ["python3", "main.py"]
browsers.json
{
"chrome": {
"default": "83.0",
"versions": {
"83.0": {
"image": "selenoid/vnc:chrome_83.0",
"port": "4444",
"path": "/"
}
}
}
}
requirements.txt
selenium~=3.141.0
Все лежит в одной директории, делаю docker-compose up
, логи докера:
20:45 $ docker-compose up
Building app
Step 1/5 : FROM python:3.7-alpine
---> 6ca3e0b1ab69
Step 2/5 : WORKDIR /usr/src/app
---> Using cache
---> bdc846c19e10
Step 3/5 : COPY requirements.txt ./
---> Using cache
---> a4c313aecb0a
Step 4/5 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
---> 3dd3cb308c0f
Step 5/5 : COPY . .
---> 88ba36765c76
Successfully built 88ba36765c76
Successfully tagged untitled_app:latest
WARNING: Image for service app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating untitled_app_1 ... done
Creating untitled_selenoid_1 ... done
Attaching to untitled_selenoid_1, untitled_app_1
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Loading configuration files...]
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Loaded configuration from /etc/selenoid/browsers.json]
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Video Dir: /opt/selenoid/video]
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Your Docker API version is 1.40]
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Timezone: UTC]
selenoid_1 | 2020/07/05 17:46:28 [-] [INIT] [Listening on :4444]
app_1 | Traceback (most recent call last):
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
app_1 | (self._dns_host, self.port), self.timeout, **extra_kw
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
app_1 | raise err
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
app_1 | sock.connect(sa)
app_1 | ConnectionRefusedError: [Errno 111] Connection refused
app_1 |
app_1 | During handling of the above exception, another exception occurred:
app_1 |
app_1 | Traceback (most recent call last):
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
app_1 | chunked=chunked,
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
app_1 | conn.request(method, url, **httplib_request_kw)
app_1 | File "/usr/local/lib/python3.7/http/client.py", line 1262, in request
app_1 | self._send_request(method, url, body, headers, encode_chunked)
app_1 | File "/usr/local/lib/python3.7/http/client.py", line 1308, in _send_request
app_1 | self.endheaders(body, encode_chunked=encode_chunked)
app_1 | File "/usr/local/lib/python3.7/http/client.py", line 1257, in endheaders
app_1 | self._send_output(message_body, encode_chunked=encode_chunked)
app_1 | File "/usr/local/lib/python3.7/http/client.py", line 1028, in _send_output
app_1 | self.send(msg)
app_1 | File "/usr/local/lib/python3.7/http/client.py", line 968, in send
app_1 | self.connect()
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in connect
app_1 | conn = self._new_conn()
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 172, in _new_conn
app_1 | self, "Failed to establish a new connection: %s" % e
app_1 | urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fe12e509890>: Failed to establish a new connection: [Errno 111] Connection refused
app_1 |
app_1 | During handling of the above exception, another exception occurred:
app_1 |
app_1 | Traceback (most recent call last):
app_1 | File "main.py", line 12, in <module>
app_1 | desired_capabilities=capabilities
app_1 | File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
app_1 | self.start_session(capabilities, browser_profile)
app_1 | File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
app_1 | response = self.execute(Command.NEW_SESSION, parameters)
app_1 | File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
app_1 | response = self.command_executor.execute(driver_command, params)
app_1 | File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
app_1 | return self._request(command_info[0], url, body=data)
app_1 | File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 402, in _request
app_1 | resp = http.request(method, url, body=body, headers=headers)
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 80, in request
app_1 | method, url, fields=fields, headers=headers, **urlopen_kw
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 171, in request_encode_body
app_1 | return self.urlopen(method, url, **extra_kw)
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 336, in urlopen
app_1 | response = conn.urlopen(method, u.request_uri, **kw)
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 765, in urlopen
app_1 | **response_kw
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 765, in urlopen
app_1 | **response_kw
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 765, in urlopen
app_1 | **response_kw
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
app_1 | method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
app_1 | File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
app_1 | raise MaxRetryError(_pool, url, error or ResponseError(cause))
app_1 | urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe12e509890>: Failed to establish a new connection: [Errno 111] Connection refused'))
untitled_app_1 exited with code 1
Гуглеж уже несколько часов не помогает. Если, например, закомментить этот питонячий код и попробовать вывести только один print, то все работает, гуру селеноида хелп!!!
from selenium import webdriver
import time
capabilities = {
"browserName": "chrome",
"version": "83.0",
"platform": "LINUX",
}
#driver = webdriver.Remote(
# command_executor="http://0.0.0.0:4444/wd/hub",
# desired_capabilities=capabilities
#)
if __name__ == "__main__":
# driver.get("https://google.com")
# time.sleep(3)
# driver.save_screenshot("test.png")
print("Success!")
20:50 $ docker-compose up
Building app
Step 1/5 : FROM python:3.7-alpine
---> 6ca3e0b1ab69
Step 2/5 : WORKDIR /usr/src/app
---> Using cache
---> bdc846c19e10
Step 3/5 : COPY requirements.txt ./
---> Using cache
---> a4c313aecb0a
Step 4/5 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
---> 3dd3cb308c0f
Step 5/5 : COPY . .
---> d1fd0ebd98b5
Successfully built d1fd0ebd98b5
Successfully tagged untitled_app:latest
WARNING: Image for service app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating untitled_selenoid_1 ... done
Creating untitled_app_1 ... done
Attaching to untitled_selenoid_1, untitled_app_1
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Loading configuration files...]
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Loaded configuration from /etc/selenoid/browsers.json]
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Video Dir: /opt/selenoid/video]
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Your Docker API version is 1.40]
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Timezone: UTC]
selenoid_1 | 2020/07/05 17:51:07 [-] [INIT] [Listening on :4444]
app_1 | Success!
untitled_app_1 exited with code 0