Closed matt-jay closed 9 months ago
Docker engine includes a DNS service for networks, so that discovery of other services doesn't rely on /etc/hosts
entries.
I tried to reproduce with a simplified compose.yaml file:
services:
web:
image: alpine
command: ping db
db:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: test
hostname: db
and get the expected result:
$ docker compose up --attach web
[+] Running 2/2
✔ Container truc-db-1 Running 0.0s
✔ Container truc-web-1 Recreated 0.1s
Attaching to web-1
web-1 | PING db (172.30.0.2): 56 data bytes
web-1 | 64 bytes from 172.30.0.2: seq=0 ttl=64 time=0.653 ms
web-1 | 64 bytes from 172.30.0.2: seq=1 ttl=64 time=0.400 ms
web-1 | 64 bytes from 172.30.0.2: seq=2 ttl=64 time=0.137 ms
web-1 | 64 bytes from 172.30.0.2: seq=3 ttl=64 time=0.620 ms
Can you please try the same ?
You also could use docker compose exec web ping db
with your application running to run a comparable test
Please also inspect immohub-db-1
container to check Networks.Aliases
is set as expected
Thanks for checking on this, @ndeloof. I successfully reproduced your simplified example. This led me to revisit my docker-compose file and it turned out that the image
definition brought the setup off course. When I remove my image: immoscreen_app
configuration, everything works as expected. I don't fully understand why, but my problem is solved.
Description
I am trying to run a Django app with a PostgreSQL database using docker-compose. However, the Django app container (
web
) does not appear to be able to connect to thedb
service. After some troubleshooting, I found out that thedb
host is not added to theweb
host's/etc/hosts
file. When adding it manually, I can successfully ping thedb
host from within theweb
container.Apparently there is an issue in the network configuration that is created by docker-compose. What might cause it?
Here is my
docker-compose.yml
file:The output of
docker inspect immohub_immohub_default
looks to me like the basic network configuration is fine.Steps To Reproduce
Run
docker compose -f docker-compose.yml up
with thedocker-compose.yml
file provided in post.Compose Version
Docker Environment
Anything else?
No response