What is:

docker-compose config

version: '2' services: web: image: nginx hostname: site.dev links: - app ports: - "80:80" app: image: php volumes: - /var/www:/var/www 

Problem:

I run the docker-composer run app curl -v site.dev and get the curl: (7) Failed to connect to site.dev port 80: Connection refused error curl: (7) Failed to connect to site.dev port 80: Connection refused . If you run the docker-composer run app curl -v web then everything is fine

Question:

How can the "app" container report that the "web" container has the domain name site.dev?

Addition:

  • it is impossible to add app links web:site.dev for the container, because it curses circular dependency
  • site.dev:172.17.0.2 can add extra_hosts like site.dev:172.17.0.2 , but you have to correct the ip address every time
  • You can create a builder where it will be added to / etc / hosts 172.17.0.2 site.dev , but the problem will be the same as in the example above
  • add dnsmasq in a separate container, the most popular image weighs eight megabytes. I have to, however, smoke the documentation on the command line, in my opinion, the -A key will be needed (and it may be necessary to extract a specific ip with a bash script) - etki
  • @Etki, the fact is that there is a docker-proxy and docker network, and I guess that the docker himself can solve these problems, but having scrolled through the dock I did not understand how. - duhon 3 hours ago - duhon

1 answer 1

In this case, you can remove the links from the web container and add it to the app with the domain alias. In this way, circular dependency can be avoided. The hostname instruction doesn’t affect the external containers in any way; this is the sign inside the container name that appears only if you go into bash

 version: '2' services: web: image: nginx ports: - "80:80" app: image: php links: - web:site.dev volumes: - /var/www:/var/www 

if you need to make links from two sides, that is

 version: '2' services: web: image: nginx ports: - "80:80" links: - app:site2.dev app: image: php links: - web:site.dev volumes: - /var/www:/var/www 

ERROR: Circular dependency between web and app will occur, so far it can be solved with the extra_hosts option