Docker-compose: Failed to establish a new connection: [Errno 111] Connection refused'

Trying to run test_ui from docker-compose

docker-compose.yml:

version: “3”
services:
test_ui:
image: test_ui
container_name: test_ui
build: .
volumes:
- ./allure-results:/allure-results/
selenoid:
image: “aerokube/selenoid”
container_name: selenoid
network_mode: bridge
restart: always
ports:
- “4444:4444”
volumes:
- “.:/etc/selenoid/”
- “/var/run/docker.sock:/var/run/docker.sock”
selenoid-ui:
image: “aerokube/selenoid-ui”
container_name: selenoid-ui
network_mode: bridge
restart: always
links:
- selenoid
ports:
- “8080:8080”
command: [ “–selenoid-uri”, “http://selenoid:4444” ]

Dockerfile:
FROM python:3.10.6-slim-buster
COPY . lamoda/
WORKDIR lamoda
RUN apt-get update -y && apt-get install -y python3-pip
RUN pip install -r requirements.txt
CMD [“sh”, “-c”, “python3 -m pytest -s --alluredir=./allure-results tests/test_auth.py”]

I get such an error:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘localhost’, port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fbfa6327280>: Failed to establish a new connection: [Errno 111] Connection refused’))

I can’t understand what is the problem?

The post is not formatted properly, which makes it hard to read. Please format it according this post: How to format your forum posts

Why would you expect the test_ui service to reach the application of the selenoid service using localhost?

Localhost of a container is not the same localhost of the host or any other container.

Please do not use network_mode: bridge, as it will put all containers into the default docker bridge network (not to confuse with a default network docker compose creates for this project). The default docker bridge network does not support dns-based service discovery. Remove this setting for all declared service and let the containers use the default network docker compose creates for you, as it provides service discovery.

Then use the service name of the target service to communicate with it:
Instead of HTTPConnectionPool(host=‘localhost’, port=4444), it must be HTTPConnectionPool(host=‘selenoid’, port=4444).

Removed network_mode: bridge,
instead of ‘localhost’ wrote ‘selenoid’
as a result, the container was launched, but it crashed with an error:

Failed to read: session.ignoreBorder
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.forcePseudoTransparency
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.colorsPerChannel
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.doubleClickInterval
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.tabPadding
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.styleOverlay
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.slitlistFile
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.appsFile
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.tabsAttachArea
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.cacheLife
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.cacheMax
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.autoRaiseDelay
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.ignoreBorder
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.forcePseudoTransparency
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.colorsPerChannel
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.doubleClickInterval
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.tabPadding
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.styleOverlay
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.slitlistFile
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.appsFile
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.tabsAttachArea
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.cacheLife
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.cacheMax
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:34 Failed to read: session.autoRaiseDelay
2023-01-23 20:14:34 Setting default value
2023-01-23 20:14:35 — x11vnc loop: waiting for: 56

response = {‘status’: 500, ‘value’: ‘{“value”:{“error”:“session not created”,“message”:“wait: http://172.17.0.2:4444 does not respond in 30s”}}\n’}

Please read the beginning of @meyay’s post and the topic that he linked.

About the eror message: What does the “status” mean? if the status is an HTTP status, you should see log messages in the selenoid container. HTTP 500 is internal server error.