How to block outbound network and internet access for a Docker container
Whether you want to prevent a docker container to spy on your sensitive data with invasive telemetry or want to restict internet access for security reasons, here is how to do it.
First you need to create an internal
network:
$ docker network create --internal --subnet 172.19.0.0/16 no-internet
Then you can launch your container with this new no-internet
network attached:
$ docker run -d --network no-internet --name my_container my/image:latest
Alternatively, you can detach an already running container from the bridge
network and attach the new network:
$ docker network disconnect bridge [my_container]
$ docker network connect no-internet [my_container]