Docker containers have no internet, I've tried many solutions

删除回忆录丶 提交于 2020-03-05 03:24:18

问题


I have docker containers running on Ubuntu 16.04 on Digital Ocean. They worked well but one day (I think it happened after TOR1 Droplet Reboot 2018-02-28 16:00 UTC [Spectre and Meltdown Mitigation] but I'm not sure) they have lost their internet connection and I do not know why and how to make it work.
I have tried many different solutions from other answers but without success. I have tried the answers from this question, tried to disable ufw, tried to reboot OS. I have even tried to update Docker and Ubuntu in hope it will finally work but it did not.
I suspect it may be problem with iptables but I do not know what to do with it.
There was a sh script on the server named iptable.rules.sh with the following content:

#/bin/sh
#blow away the DOCKER chain
sudo iptables -F DOCKER

#add http / https
sudo iptables -A DOCKER -p tcp --dport https -j ACCEPT -d 172.17.0.4
sudo iptables -A DOCKER -p tcp --dport http -j ACCEPT -d 172.17.0.4

#loopback for mongodb
sudo iptables -A DOCKER -p tcp --dport 27017 -j ACCEPT -d 172.17.0.2 -i lo

But when I run it, it says:

iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.

The only way I can run a container with internet connection is using --net=host, but I cannot because of linked containers.

So I am stumped and asking you for help.


回答1:


The problem was in Docker updating, instance rebooting and the file /etc/docker/daemon.json with {"iptables": false} created by the previous maintainer. These things were overlapped by each other.

I have found the solution in this answer.
Or more described in this article.



来源:https://stackoverflow.com/questions/49284727/docker-containers-have-no-internet-ive-tried-many-solutions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!