First of all, I start docker with the command:
docker --iptables=false -d
When I want to start my docker container, I start it like this
docker run --net=host myImageName
Use the host of net mode can make me access internet from the docker container.
But when I write dockerFile, I can't make it start in host mode.
So how can I access internet in the docker build.
In addition, I must run docker in the mode --iptables=false, because I don't have nat table in iptables. And I don't want it.(Reason link)
So in this mode, how can I access internet in the dockFile build.
DEFAULT_FORWARD_POLICY="ACCEPT"
@ /etc/default/ufw
/etc/ufw/before.rules
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
COMMIT
I, as many people, had to add --iptables=true
to make sure my UFW rules were respected by Docker. But all the articles seem leave out out an important thing that is... the time you reboot your machine, a series of configurations done when you enabled that setting on-the-fly and rebooted the Docker Engine will be lost. The problem? Your containers will no longer connect to the internetz.
Eventually I found out an article with a "full solution". You can find it here and it basically tells you what I wrote at the beginning of the answer.
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With