+1 vote
ago by
I'm running a codeception test.
I use webdriver browser: chrome.

The problem is that I have several domains that chrome can't see inside the container.
That is, by host.docker.internal, by IP of container nginx 172.20.08 opens project, but you need to open by domain name.
The domains in the configs are rolled. If you go inside the container (docker exec -it), curl on the domain names works correctly.
Chrome connects to containers - it works by IP. So there is nothing wrong with the network.
But as soon as I connect by domain name from chrome, the error "This site cant' be reached. ERR_CONNECTION_REFUSED"

My configs:

docker-compose.yml
version: '3.3'
networks:
mynetworkname:
ipam:
config:
- subnet: 172.20.0.0/24
services:
nginx:
container_name: my-nginx
image: nginx:1.18
ports:
- 80:80
- 443:443
restart: always
volumes:
- ./:/srv/localhost/src/
- ./docker-nginx/ssl-params.conf:/etc/nginx/snippets/ssl-params.conf
- ./docker-nginx/self-signed.conf:/etc/nginx/snippets/self-signed.conf
- ./docker-nginx/nginx-selfsigned.crt:/etc/ssl/certs/nginx-selfsigned.crt
- ./docker-nginx/nginx-selfsigned.key:/etc/ssl/private/nginx-selfsigned.key
- ./docker-nginx/dhparam.pem:/etc/nginx/dhparam.pem

- ./docker-nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker-nginx/conf.d:/etc/nginx/conf.d
- ./logs/nginx:/var/log/nginx
depends_on:
- php
networks:
mynetworkname:
ipv4_address: "172.20.0.8"
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"
php:
container_name: my-php
build: docker-php
restart: always
image: php:7.4-fpm
volumes:
- ./:/srv/localhost/src/
- ./logs/php:/var/log
expose:
- 9001
- 9000
depends_on:
- mariadb
networks:
mynetworkname:
ipv4_address: "172.20.0.9"
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"

mariadb:
container_name: my-mariadb
image: mariadb:10.3
restart: always
volumes:
- ./docker-mysql/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: XXXX
ports:
- 33061:3306
networks:
mynetworkname:
ipv4_address: "172.20.0.10"
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"

phpmyadmin:
container_name: pma
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
environment:
MYSQL_ROOT_PASSWORD: XXXXX
PMA_HOST: mariadb
PMA_PORT: 3306
depends_on:
- mariadb
networks:
mynetworkname:
ipv4_address: "172.20.0.11"
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"
selenium-hub:
image: selenium/hub:3.12.0-cobalt
container_name: selenium-hub
ports:
- 4444:4444
networks:
- mynetworkname
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"
chrome:
image: selenium/node-chrome:3.12.0-cobalt
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks:
- mynetworkname
extra_hosts:
- "site0.localhost:172.20.0.8"
- "site1localhost:172.20.0.8"
- "php:172.20.0.9"
- "mariadb:172.20.0.10"
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
# url: https://172.20.0.8:443 - работает
#url: https://site1.localhost:443 - не работает. Валит ошибку
url: http://host.docker.internal/
host: selenium-hub
browser: chrome
capabilities:
acceptInsecureCerts: true # allow self-signed certificates

1 Answer

0 votes
ago by
 
Best answer
It was worth getting desperate to write here, and the solution caught up with me.
The problem was domain names ending in localhost.
Replaced everything with .local and it worked.
As I understand it, it's about docker - for it domainname.localhost is something special. The .localhost suffix is handled in its own way.
I didn't know...
...