From 1cea9c1c87e200dafeb7f8ab41c8145c199aa59c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 21 Jan 2016 16:24:01 +0000 Subject: [PATCH] Extract function to detect container running in host namespace --- weave | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weave b/weave index 5f09dc04..75d3648e 100755 --- a/weave +++ b/weave @@ -833,8 +833,12 @@ setup_router_iface_bridged_fastdp() { setup_router_iface_fastdp "$@" } +container_in_host_ns() { + [ -h "$PROCFS/$CONTAINER_PID/ns/net" -a -h "/proc/self/ns/net" -a "$(readlink $PROCFS/$CONTAINER_PID/ns/net)" = "$(readlink /proc/self/ns/net)" ] +} + attach() { - if [ -h "$PROCFS/$CONTAINER_PID/ns/net" -a -h "/proc/self/ns/net" -a "$(readlink $PROCFS/$CONTAINER_PID/ns/net)" = "$(readlink /proc/self/ns/net)" ] ; then + if container_in_host_ns ; then echo "Container is running in the host network namespace, and therefore cannot be" >&2 echo "connected to weave. Perhaps the container was started with --net=host." >&2 return 1