jlazkano
(Jlazkano)
April 16, 2020, 8:39am
1
Hello,
I just create a network to put there my containers.
I use nginx to proxy all http requests to diferents containers.
The problems is that if I delete and create some containers, the IP change in the containers.
Is there any way to fix the same IP always to a container? Something like DHCP does with MAC address?
Best regards.
sebt3
(Sebt3)
April 16, 2020, 4:21pm
2
Docker run a small dns server for your containers. So each containers can resolve the name (to IP address obviously) of the others containers in their networks.
Do not use IP address in your nginx.conf
but the name of the containers
1 Like
jlazkano
(Jlazkano)
April 16, 2020, 8:38pm
3
Thanks!
That is a good idea, thanks for your reply.
Best regards.
jlazkano
(Jlazkano)
April 17, 2020, 1:40pm
4
Hello,
I need to flush the docker DNS server, I had stop and start some dockers and the IP assigned has changed. But the name is traslating the old IP.
Is there any way to flush the docker internal DNS?
Best regards.
sebt3
(Sebt3)
April 17, 2020, 2:41pm
5
I never had such issue : it’s always up-to-date.
$ docker network inspect public
....
"Containers": {
"9ddc0926fafb9bc4fd7ca8fc8929c49c1a3209f756461ce6f0f0177db8521b2d": {
"Name": "nextcloud_nginx.1.jsw8k07l4pbwfj0219hqj1y9v",
"EndpointID": "bc3c744ac3d4ff082136bd6aeb4e01eebaf0e1f797fdcee488284d569d67ca94",
"MacAddress": "02:42:0a:00:01:02",
"IPv4Address": "10.0.1.2/24",
"IPv6Address": ""
},
"ad841f0975d0a2f248c968a82330ab4a0cdc374f97c760eb851c7c3fc6bbe55f": {
"Name": "hubzilla_nginx.1.x78gw0hbxqw6zk4wallevfvby",
"EndpointID": "9212203992b8ecebb6f0fa83617da76a022055f02ea08fc869d84258fd4e1f08",
"MacAddress": "02:42:0a:00:01:05",
"IPv4Address": "10.0.1.5/24",
"IPv6Address": ""
},
....
$ docker exec -it hubzilla_nginx.1.x78gw0hbxqw6zk4wallevfvby ping nextcloud_nginx
PING nextcloud_nginx (10.0.1.99): 56 data bytes
64 bytes from 10.0.1.99: seq=0 ttl=64 time=0.128 ms
....
Indeed 10.0.1.99
is not the final 10.0.1.2
because it’s the service IP not the container IP, yet in the end it is the right container that reply (and that will allow you to scale up the service at will if needed)