One needs to do network debugging at some point in life, for answering questions like: is my application connecting to the Internet somehow?

This time I’m going to debug a PHP script running on a docker container.

1. Running a network debugging container

$ docker run --name netdbg -ti --net container:[name] -v /tmp:/tmp jonschipp/tcpdump-sandbox tcpdump -s0 -peni eth0 -w/tmp/capture.pcap

In the example above, a container image with everything we need is downloaded in order to create a new container named netdbg. Then it triggers tcpdump which saves the capture to /tmp/capture.pcap in your host machine! Long life to one-liners!

NOTICE: “–net container:[name]” does the magic, make sure that [name] correspond to an already running container (the one that has the stuff we want to debug).

2. Displaying the output

Run your PHP code, that will fire network activity. Now, do you remember the file /tmp/capture.pcap, let’s run wireshark and open that file. There you’ll have lot’s of options to filter the records.

Enjoy!

Why containerization is great for network debugging

Honestly I’m not a network expert, but AFAIK, docker is doing great job at isolating the network traffic of each container, so that network debugging tools don’t access lots of network records that are useless (stuff running on your host machine: Internet browsers, chats, e-mail clients, etc). That is huge! isn’t it?

Blessings!