Analyzing HTTPS Traffic with Containers and Tcpdump

Imran Hasan
3 min readMar 31, 2023

--

As more and more applications move to a containerized environment, it is becoming increasingly important to have tools that can help analyze network traffic and identify performance issues. In this post, we will explore how to use containers and tcpdump to capture and analyze HTTPS traffic in a containerized environment.

Step 1: Install Docker

The first step is to install Docker on your local PC. You can download and install Docker Desktop for your operating system from the Docker website.

Step 2: Create a Docker network

Next, you need to create a Docker network to connect the containers. You can create a bridge network using the command docker network create mynetwork.

Step 3: Create two containers

You can create two containers running a simple web server to simulate an application that is experiencing slow response times. You can use the following commands to create the containers:

docker run -d --name container1 --network mynetwork -p 8080:80 nginx
docker run -d --name container2 --network mynetwork -p 8081:80 nginx

The first command creates a container named container1 running the Nginx web server and exposes port 80 on the container to port 8080 on the host. The second command creates a similar container named container2 with port 80 on the container exposed to port 8081 on the host.

Step 4: Install tcpdump

You need to install tcpdump on both containers to capture traffic. You can use the command apt-get update && apt-get install -y tcpdump to install tcpdump on the containers.

Step 5: Start a tcpdump capture

Once tcpdump is installed, you can start a capture session on the containers to capture HTTPS traffic. You can use the command tcpdump -i eth0 -s 0 -w capture.pcap port 443 to capture HTTPS traffic on port 443 and write it to a file named capture.pcap.

Step 6: Send HTTPS requests

With tcpdump running, you can send HTTPS requests to the containers to simulate the performance issue. You can use a web browser or a command-line tool like curl to send HTTPS requests to https://localhost:8080 and https://localhost:8081 to trigger the slow response times.

Step 7: Stop the tcpdump capture

Once you have reproduced the performance issue, you can stop the tcpdump capture by pressing Ctrl+C on the terminal where tcpdump is running.

Step 8: Analyze the captured packets

You can now analyze the captured packets using tools like Wireshark or tcpdump itself. You can copy the capture.pcap file from the containers to your local PC using the command docker cp container1:/capture.pcap . and docker cp container2:/capture.pcap . to copy the file from container1 and container2 respectively. You can then open the file in Wireshark or use the command tcpdump -r capture.pcap to view the captured packets in the terminal.

Step 9: Identify the root cause

With the captured packets, you can analyze the traffic to identify the root cause of the performance issue. You can look for factors like network latency, server load, or application code to pinpoint the root cause of the issue.

Step 10: Take corrective action

Based on the analysis results, you can then take corrective action to resolve the issue. This may involve optimizing network settings, scaling up resources,

--

--

Imran Hasan
Imran Hasan

Written by Imran Hasan

DevOps Engineer - Building, Deploying and Scaling Software Solutions.

No responses yet