Is there a way to add a Docker host to the / etc / hosts container using docker-compose?

TL DR Is there an easy way to assign a docker node address for a host name in a container for docker build?

I use a selenium concentrator for testing while working in a Docker container. On my dev machine, I see my web application in http://localhost:8080, but in the context of the selenium hub is localhostnot available. I would like to write my tests so that I can use the URL, for example http://dockerhost:8080/, to test the application.

The wrinkle is that the development of this code takes place on several machines, some of which are located in different networks, in different places, etc. Therefore, I would like to do this in such a way that there is not docker-compose.ymlfor every host where it can be started.

I have a selenium hub and browser images in a separate docker-compose.yml file from my application, which looks something like this:

hub:
    image: selenium/hub
    ports:
        - 4444:4444
    extra_hosts:
        dockerhost: 1.2.3.4

firefox:
    image: selenium/node-firefox
    links:
        - hub
    extra_hosts:
        dockerhost: 1.2.3.4

chrome:
    image: selenium/node-chrome
    links:
        - hub
    extra_hosts:
        dockerhost: 1.2.3.4

This works, but requires the file to be docker-compose.ymlupdated with IP addresses on each host. Given that the file is docker-compose.ymlbound to the repository gitfor the project, this is unacceptable.

, , IP- - ( ? - docker-compose?), IP-, docker-compose up. , , , .

1.2.3.4 DOCKER_HOST :

# in the docker-compose.yml file
extra_hosts:
    dockerhost: $DOCKER_HOST

# run docker-compose up on the command line
DOCKER_HOST=1.2.3.4 docker-compose up

. , - . docker-compose.yml bash IP- :

extra_hosts:
    dockerhost: $(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+')

, , , .

?

+4

Source: https://habr.com/ru/post/1663523/


All Articles