Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

518
Views
How to disable network for a running Docker container?

I would like to start a Docker container normally, run it, install some things into it, and then I would like to disable the network, to run some more commands in it, but they should not have access to the network. How can I do that for a running container?

I use docker-py and I know I can use network_disabled to disable networking for the whole container. But I am not sure how I can disable the network after the container is already created. Ideally, I would run the container with command sleep infinity, then docker exec some commands in it, then disable networking, then run few more commands using docker exec.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Maybe an option would be docker network disconnect

Description

Disconnect a container from a network

Usage

docker network disconnect [OPTIONS] NETWORK CONTAINER

Example:

Create a container attached to the default bridge network

docker container run --rm -it alpine ping 8.8.8.8

and after a while disconnect it with:

docker network disconnect bridge <container-name>

enter image description here

over 4 years ago · Santiago Trujillo Report

0

The standard pattern you should use here is to write a Dockerfile that does whatever software installation you need, and builds an image out of it. This actually fits your immediate need quite nicely, since once you've built the image you can run it without network.

A typical Dockerfile skeleton might look more or less like

FROM ubuntu:18.04
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install --no-install-recommends --assume-yes \
      thing-to-run-without-network
CMD ["/usr/bin/thing-to-run-without-network"]

And then you'd build and run it as

docker build -t no-net-test .
docker run --rm --net none no-net-test

Generally you should set your image up so that docker run does everything the container needs to do, without needing to docker exec ever (except for hand debugging). You should never install things into a running container: your work will get lost as soon as you docker rm the container, and deleting and restarting your containers is extremely routine.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!