#!/bin/bash set -e echo "=== Cleaning up old containers ===" docker rm -f bridge-demo host-demo 2>/dev/null || true echo "=== Starting container in default bridge network ===" docker run -d --name bridge-demo --rm alpine sleep 300 echo "=== Starting container in host network ===" docker run -d --name host-demo --network host --rm alpine sleep 300 echo echo "=== Showing Docker bridge (docker0) info ===" ip addr show docker0 brctl show docker0 || true echo echo "=== Finding network namespace of bridge-demo container ===" BRIDGE_PID=$(docker inspect -f '{{.State.Pid}}' bridge-demo) echo "bridge-demo PID: $BRIDGE_PID" ls -l /proc/$BRIDGE_PID/ns/net echo echo "=== Interfaces inside bridge-demo namespace ===" nsenter --net=/proc/$BRIDGE_PID/ns/net ip addr echo echo "=== veth pair mapping for bridge-demo ===" # The host-side veth will have a name like vethXXXX HOST_VETH=$(ip link | grep -B1 "@if" | grep veth | awk '{print $2}' | tr -d :) echo "Host veth: $HOST_VETH" echo echo "=== Network namespace of host-demo container ===" HOST_PID=$(docker inspect -f '{{.State.Pid}}' host-demo) echo "host-demo PID: $HOST_PID" ls -l /proc/$HOST_PID/ns/net echo echo "=== Interfaces inside host-demo namespace (same as host) ===" nsenter --net=/proc/$HOST_PID/ns/net ip addr echo echo "=== Routing table for bridge-demo ===" nsenter --net=/proc/$BRIDGE_PID/ns/net ip route echo echo "=== Routing table for host-demo ===" nsenter --net=/proc/$HOST_PID/ns/net ip route echo echo "=== Cleanup ===" #docker rm -f bridge-demo host-demo