I am building a library to simulate some faults in a system. One of the faults, is to simulate a network failure, which would forbid any connection. Currently, I am using this Kotlin code to disable the container network interface:
Runtime.getRuntime().exec("ifconfig eth0 down")
// wait some time
Runtime.getRuntime().exec("ifconfig eth0 up")
When the interface is re-enabled, I am not able to restore connections with the container. I tried it on the command line, and the effect is the same:
docker run --privileged -it alpine:latest sh
/ # apk add curl
...
OK: 7 MiB in 18 packages
/ # curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
/ # ifconfig eth0 down
/ # ifconfig eth0 up
/ # curl google.com
curl: (6) Could not resolve host: google.com
Does anybody have any idea why it occurs inside a docker container?