empz
empz

Reputation: 11808

How to simulate Docker container losing internet connectivity?

I'm using Docker Desktop for Windows, running a couple of linux containers using docker-compose.

These containers communicate with each other inside their own Docker network. One of the containers is set to push some data to the cloud.

I need some easy way to test the behavior of the cluster losing internet connectivity.

I do not want to disconnect my whole computer, just the Docker containers (without stopping them).

I tried restricting access of docker-compose in Windows Firewall, but that didn't work.

How can I achieve this?

Is there any Linux command I can run inside the running container to go offline?

EDIT

@vaibhand's answer disconnect a single container from the cluster network. Making it unreachable by other containers in the cluster. I need to disconnect the cluster from internet (simulating a real world internet connection outage), while keeping the internal cluster network alive so that they can still take to each other.

Upvotes: 8

Views: 4604

Answers (1)

vaibhavnd
vaibhavnd

Reputation: 301

Use docker network ls to list available networks and then docker network disconnect <NETWORK> <CONTAINER>

Upvotes: 11

Related Questions