This post shows how to execute network commands (like ip a, ping, etc.) within a container’s network namespace without installing any additional tools.
- Get the Process ID (PID) of the Container. Use the docker inspect command to retrieve the PID of the container. This will output the PID of the container’s main process
sudo docker inspect -f '{{.State.Pid}}' <container_name_or_id>
- Use the nsenter command to enter the network namespace of the container, Replace
with the PID you obtained before.
sudo nsenter --net=/proc/<PID>/ns/net