postgresql - How does one service resolve the address of another service using docker compose, link hostname, and ports? -
i have read several questions revolving same question, due insufficient points, cannot comment on existing questions. therefore, must spawn own question thread regarding docker-compose , links.
i under impression having following in docker-compose file add 'db' container's hostfile
web: links: - db
i thinking web code establish db connection along lines of
db := sql.open("postgres", "user=foo dbname=baz host=db")
where hostname db exists in web container's /etc/hostfile , therefore resolves address reaches db container.
my web application not resolve address db running, instead resolves address (172.19.0.3) , cannot figure out has come or how fix.
docker exec $web_container_id cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.19.0.2 6f52f9e78f00
i expecting see entry db. furthermore:
docker exec $web_container_id nslookup db name: db address 1: 172.19.0.3 apiserver_postgres_1.apiserver_default
what misunderstanding? how enable web code resolve db address?
this no longer classic docker 1.8 or less "link", if using version 2 of docker-compose.yml
file.
as mentioned in issue 3002:
version:"2" creates bridge network default project. if run
docker network ls
you'll see new bridged network project containers created. (which makes totally sense)docker has removed these variables links on network except old bridge network.
there embedded dns.
Comments
Post a Comment