Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Inspecting docker activity with socat

February 25, 2015
Roland Grunberg
Related topics:
Containers

Share:

    Lately I've been busy working on an Eclipse plugin that will support a wide range of docker functionality. Some of that has involved looking at some docker client libraries, figuring out how it works in one implementation, and seeing how this can be ported to other implementations. While the Docker Remote API is well documented, it can still be tricky to get things right.

    When I'm debugging some failed interaction, I've found socat to be very useful.

    Let's say we want to inspect all traffic going through 'unix:///var/run/docker.sock' . We can't directly sniff the traffic on it as we don't really control this socket. We first create a fake unix socket, say '/tmp/fake' and relay all its traffic to '/var/run/docker.sock' . In this way, regular interactions remain undisturbed, but the redirect allows socat to inspect traffic.

    $ socat -v UNIX-LISTEN:/tmp/fake,fork UNIX-CONNECT:/var/run/docker.sock

    -v : writes the traffic to stderr as text in addition to relaying instructions. Some conversions are made for the sake of readability so if certain sequences aren't being interpreted properly, one could try -x (hex).
    UNIX-LISTEN : listen for connections on the unix socket (In our case, /tmp/fake)
    fork : create a separate subprocess for handling new connections so the main process may continue listening
    UNIX-CONNECT : connect to the specified unix socket (In our case, /var/run/docker.sock)

    Once that's been started, it's just a matter of ensuring your docker commands go through 'unix:///tmp/fake'.

    $ export DOCKER_HOST=unix:///tmp/fake
    $ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    fedora              20                  6cece30db4f9        4 weeks ago         374.1 MB

    The output should look something like this :

    $ socat -v UNIX-LISTEN:/tmp/fake,fork UNIX-CONNECT:/var/run/docker.sock
    > 2015/02/05 12:47:35.433028  length=85 from=0 to=84
    GET /v1.16/images/json HTTP/1.1r
    Host: /tmp/faker
    User-Agent: Docker-Client/1.4.1r
    r
    < 2015/02/05 12:47:35.437616  length=369 from=0 to=368
    HTTP/1.1 200 OKr
    Content-Type: application/jsonr
    Date: Thu, 05 Feb 2015 17:47:35 GMTr
    Content-Length: 260r
    r
    [{"Created":1420065245,"Id":"6cece30db4f924da43969a12fdf47492ada22b372a0968d6ca8b71d25876629f","ParentId":"782cf93a8f16d3016dae352188cd5cfedb6a15c37d4dbd704399f02d1bb89dab","RepoTags":["fedora:20","fedora:heisenbug"],"Size":374074925,"VirtualSize":374074925}

    We could have done this just as easily over TCP-LISTEN/TCP-CONNECT provided the docker service was bound to some local port but you can find out more about the various options in the man-page. Even some basic searches should demonstrate the incredible versatility of this tool.

    Last updated: August 28, 2020

    Recent Posts

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    • Benchmarking with GuideLLM in air-gapped OpenShift clusters

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue