Harris
Harris

Reputation: 1138

Docker containers lose internet randomly

I have set up 2 docker containers. One servers an angular application and the other is a .net core app that gets api calls from angular and sends them to an ERP, gets the data and pass them back to angular. It acts as a proxy. The whole thing is in development so it is not used often. Sometimes I notice docker container loses internet connection. I exec bash in the container and curl for an address and get a timeout. My host is a debian stable setup with csf firewall. I have in csf.allow my docker range address:

localhost
127.0.0.1
172.20.0.0/24

I have setup a docker network and when I docker inspect I get the containers:

"e76912e90d5f41655ec1a3ae8c62ead4f3110b9649a7f84d2c5f1d1fc4061306": {
                "Name": "backend-test",
                "EndpointID": "3a050810c3bc23a79a08ad9cadb67a0c29af901777250706d59201d305596048",
                "MacAddress": "02:42:ac:14:00:0b",
                "IPv4Address": "172.20.0.11/16",
                "IPv6Address": ""
            },
            "eeb00eb35b126023180ba5b3799b519bb6b4a1b28407b5b19858f414716ed4aa": {
                "Name": "kibana",
                "EndpointID": "c57f6d2f6cf3a12a358ab851e56fbc91ceb63f0a4c6f37cf41b45d8f794e43bc",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }

What should I check for? If I disable csf still docker container have no internet. The only thing I can do is restart docker.

Upvotes: 2

Views: 454

Answers (1)

Andy Jones
Andy Jones

Reputation: 4971

I had a similar issue. I eventually found that the /etc/resolv.conf file in my container had a different nameserver to the one given by

systemd-resolve --status | grep "DNS Server"

on my Ubuntu host. The fix for the running containers was to copy the new DNS server from the systemd-resolve --status output into /etc/resolv.conf in the containers.

For future containers, I've used the --dns switch to point the containers at a fixed, public DNS server.

I think the root cause is my mobile internet; I think I get a different DNS server whenever my phone decides to reconnect.

Upvotes: 1

Related Questions