For an unknown reason, I ran into a docker error when I tried to run a docker-compose up
on my project this morning.
My web container isn't able to connect to the db host and nc
still returning
web_1 | nc: bad address 'db'
There is the relevant part of my docker-compose definition:
version: '3.2'
services:
web:
build: ./app
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./app/:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=
- POSTGRES_PASSWORD=
- POSTGRES_DB=
mailhog:
# mailhog declaration
volumes:
postgres_data:
I've suspected the network to be broken and it actually is. This is what I get when I inspect the docker network relative to this project: ( docker network inspect my_docker_network
)
[
{
"Name": "my_docker_network",
"Id": "f09c148d9f3253d999e276c8b1061314e5d3e1f305f6124666e2e32a8e0d9efd",
"Created": "2020-11-18T13:30:29.710456682-05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {}, // <=== This is empty !
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "my-project"
}
}
]
Docker: 18.09.1, build 4c52b90
Docker-compose: 1.21.0, build unknown
I was able to fix that by running docker-compose down && docker-compose up
but it could be kinda bad if your down was removing all your volumes and so, your data...
The inspection of networking is now alright:
[
{
"Name": "my_docker_network",
"Id": "236c45042b03c3a2922d9a9fabf644048901c66b3c1fd15507aca2c464c1d7ef",
"Created": "2020-12-04T12:04:40.765889533-05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"0939787203f2e222f2db380e8d5b36928e95bc7242c58df56b3e6e419efdd280": {
"Name": "my_docker_db_1",
"EndpointID": "af206a7e957682d3d9aee2ec0ffae2c51638cbe8821d3b20eb786165a0159c9d",
"MacAddress": "02:42:ac:13:00:02",
"IPv4Address": "172.19.0.2/16",
"IPv6Address": ""
},
"ae90bd27539e89d0b26e0768aec765431ee623f45856e13797f3ba0262cca3f2": {
"Name": "my_docker_web_1",
"EndpointID": "09b5cefed6c5b49d31497419fd5784dcd887a23875e6c998209615c7ec8863f4",
"MacAddress": "02:42:ac:13:00:04",
"IPv4Address": "172.19.0.4/16",
"IPv6Address": ""
},
"f2d3e46ab544b146bdc0aafba9fddb4e6c9d9ffd02c2015627516c7d6ff17567": {
"Name": "my_docker_mailhog_1",
"EndpointID": "242a693e6752f05985c377cd7c30f6781f0576bcd5ffede98f77f82efff8c78f",
"MacAddress": "02:42:ac:13:00:03",
"IPv4Address": "172.19.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "my_docker_project"
}
}
]
But: Does someone have any idea of what happened and how to prevent this problem to reappear?
I had the same problem, but with rabbitmq service in my compose file. At first I solved it by deleting all existing container and volumes on my machine, but later I updated the rabbitmq image version to latest in docker-compose.yml
:
image: rabbitmq:latest
and the problem did not reappear afterwards...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.