How can I avoid container IP changes breaking Pangolin after a VPS restart?
Asked by
VelvetCactus42
I'm running Pangolin on a VPS with several Docker containers, and they're currently configured with network_mode: pangolin. After the VPS restarts, Docker assigns different IP addresses to the containers, so Pangolin keeps trying to use the old addresses and returns bad gateway errors. Is there a way to assign stable IP addresses in Docker Compose without creating a separate network for every container, or is there a better way to configure the services?
Answers
Using network_mode for every container is probably the wrong setup. Only the relevant Pangolin proxy service should share the special network namespace, such as network_mode: service:gerbil if that is what the stack requires. The other containers should share a normal user-defined Docker network with the appropriate Pangolin or Newt service. Dockerโs built-in DNS can then resolve them by service name. Sharing one network namespace across everything can also cause port conflicts.
Reply to this answer
A macvlan network would give containers addresses on the physical network, but it doesnโt really solve this problem and is often awkward on a VPS. Container IPs are expected to change; applications should normally connect through Docker DNS and service names instead. Static IPs are mainly useful when something outside Docker cannot use DNS or service discovery.
Reply to this answer
You generally shouldnโt configure Pangolin to connect to containers by their changing IP addresses. Use the container or service name insteadโDockerโs internal DNS will resolve that name to the current container IP after a restart. That way, Pangolin continues reaching the right service even when Docker assigns a new address.
Reply to this answer
Add your answer
Answers are reviewed before publication.
VelvetCactus42: That fixed it. I didnโt realize Pangolin could use the container name as the address, but it works after restarting the VPS now.