I want to disable all outgoing connections that are initiated by docker containers to the outside world. I can do this in linux by adding a rule to the FORWARD chain in linux. How do I do this in Docker for Mac?
I found out that Docker for Mac uses an xhyve vm and that’s where docker0 interface lives. What interface in the host does this connect to? I used nettop on Mac and I see that Docker uses my en0 wireless interface. But, I’m not sure if Docker and xhyve are using the same interface.
Edit: Added docker-for-windows tag because they might have similar solutions (Hoping)
Edit 2: Docker for Mac has changed so the accepted solution changed a bit
Docker
This and the rules could be turned into a
Dockerfileand run with a-- restartoption. I thinkon-failuremight work to reapply the rules when Docker for Mac starts up.Virtual Machine
To get to the linux VM:
Since the move to linuxkit, this is not your average linux host, everything's a container:
Use
runcto move into thedocker-ce(ordocker) namespaceNote that rules will disappear after a restart of Docker for Mac. I haven't found the secret sauce for persisting system changes yet.
Use ctrl-a then d to exit the screen session otherwise you will bork the terminal.
OSX
For the easy but € option, use Little Snitch and block outbound connections on OSX from
com.docker.supervisor via vpnkit.