N
N
Nikolay Lapshin2021-03-26 02:14:24
Google Chrome
Nikolay Lapshin, 2021-03-26 02:14:24

How to run codeception tests in webdriver on docker so that chrome sees the project not by 172.20.0.8, but by the hostname specified in extra_hosts?

I am running an acceptance test on codeception.
I am using webdriver browser: chrome.

The problem is that I have several domains that chrome does not see inside the container.
That is, by host.docker.internal, by the IP of the nginx container 172.20.08, the project opens, but it needs to be opened by the domain name.
Domains in configs are thrown. If you go inside the container (docker exec -it), then curl by domain names works correctly.
Chrome connects to containers - it works by IP. So the network is all right.
But at the same time, as soon as I connect by domain name from chrome, I get 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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Lapshin, 2021-03-26
@madmaker

It was worth despairing and writing here, as the decision overtook me.
The problem was with domain names ending in localhost.
Replaced everything with .local and it worked.
As I understand it, it's about docker - domainname.localhost is something special for it. The .localhost suffix is ​​handled differently.
I did not know...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question