Search code examples
network-programmingdocker

How to capture packets for single docker container


There are many containers running on the host, and I want to capture the packets for one of them. Is there any way to do this?


Solution

  • You can bind to the network namespace of one container to another:

    docker run -it --rm --net container:<container_name> \
      nicolaka/netshoot tcpdump ...
    

    To see more about the netshoot image used above, see: https://github.com/nicolaka/netshoot