This post is to illustrate how to access the docker container’s network namespace.
1. Identify the docker container id you want to access and run below command as root on host.
# docker ps
2. Get docker container’s PID:
# pid=$(docker inspect -f '{{.State.Pid}}' ${container_id})
3. Create netns directory:
# mkdir -p /var/run/netns/
4. Create the name space softlink:
# ln -sfT /proc/$pid/ns/net /var/run/netns/[container_id]
5. Run ip netns command to access this name space. For example:
# ip netns exec [container_id] ip a