The other day I needed to log the API calls made from my Docker client to debug a difference in behavior between the docker command-line tool and the docker-py Python client. Here’s how I did it.
Disable TLS on boot2docker
I’m using boot2docker on OS X. I disabled TLS to simplify things. To disable TLS:
boot2docker ssh sudo -i echo DOCKER_TLS="no" > /var/lib/boot2docker/profile exit exit boot2docker start
You’ll also need to update environment variables:
The IP address of your boot2docker instance may be different, you can do
boot2docker ip to find out what the IP is onyour system.
Run mitmproxy as a reverse proxy
Tell your docker client to connect to mitmproxy
By default, mitmproxy listens on port 8000, so point your Docker client there:
Note that we’re hitting localhost (127.0.0.1) and not the IP address of the boot2docker instance.
Save request/response bodies
When you interact using the docker client, the requests and responses should be captured by mitmproxy. Hit “tab” to toggle between request and response, and hit “B” to save the request or response body that you’re currently viewing.