Docker: limit outgoing connections to the localhost only, while allowing all incoming connections

  docker, firewall, iptables, networking

Some programs in my docker container are making unwanted requests to e.g. Google Analytics and other tracking software, sharing my information. I want to block all this traffic, while still being able to access the docker from outside.

I tried adding the –network=host, this worked correctly, only allowing localhost access from inside the container, but also blocked all external incoming connections.

Is there a way to limit the outgoing connections to the localhost only, while still allowing incoming external connections? I only want to enforce this on a specific docker container, not for my entire system.

Any feedback is appreciated.

Source: Docker Questions