Originally my docker container was able to reach the external internet (This is a docker service/container running on an Amazon EC2).
Since my app is an API, I followed up the creation of my container (it succeeded in pulling all the packages it needed) with updating my IP Tables to route all traffic from port 80 to the port that my API (running on docker) was listening on.
Then, later when I tried rebuilding the container it failed. After much struggle, I discovered that my previous step (setting the IPTable port forwarding rule) messed up the docker's external networking capability.
Solution: Stop your IPTable service:
sudo service iptables stop
Restart The Docker Daemon:
sudo service docker restart
Then, try rebuilding your container. Hope this helps.
Follow Up
I completely overlooked that I did not need to mess with the IP Tables to forward incoming traffic to 80 to the port that the API running on docker was running on. Instead, I just aliased port 80 to the port the API in docker was running on:
docker run -d -p 80:<api_port> <image>:<tag> <command to start api>
sysctl -w net.ipv4.ip_forward=1
(on Centos 6) – qwertzguy Oct 5 '15 at 14:01sysctl -w net.ipv4.ip_forward=1
– Reeebuuk Feb 9 '19 at 13:13/etc/resolv.conf
on the host machine – Hanxue Aug 27 '19 at 10:09sysctl -w net.ipv4.ip_forward=1
I had to runsudo service docker restart
. – Asif Ali Feb 24 '20 at 9:43