Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Inspecting docker activity with socat

February 25, 2015
Roland Grunberg
Related topics:
Containers

    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

    • Protect data offloaded to GPU-accelerated environments with OpenShift sandboxed containers

    • Case study: Measuring energy efficiency on the x64 platform

    • How to prevent AI inference stack silent failures

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.