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?
3 Answers
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.
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.
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.

That fixed it. I didn’t realize Pangolin could use the container name as the address, but it works after restarting the VPS now.