liveBook · Manning

Docker.sock

As explained in Learn Docker in a Month of Lunches, Second Edition

A Docker socket is a local interprocess communication endpoint through which clients access the Docker API on Linux.

docker.sock is a private Linux communication endpoint for the local Docker API. The Docker CLI uses it by default, and a container can access it when the socket is bind-mounted. section 11.2

Mounting the socket enables practical automation:

  • A Jenkins container can run Docker and Docker Compose commands against the host’s Docker Engine. section 11.2
  • Applications inside containers can query Docker, start containers, and stop containers. section 11.2
  • The equivalent Windows connection uses the Docker Engine named pipe rather than /var/run/docker.sock. section 11.2
Listing 11.1 Binding the Docker CLI in Jenkins to the Docker Engine
# docker-compose.yml
services:
  jenkins:
    image: diamol/jenkins:2e
    ports:
      - "8080:8080"
    networks:
      - infrastructure

# docker-compose-linux.yml
jenkins:
  volumes:
    - type: bind
      source: /var/run/docker.sock
      target: /var/run/docker.sock

# docker-compose-windows.yml
jenkins:
  volumes:
    - type: npipe
      source: \\.\pipe\docker_engine
      target: \\.\pipe\docker_engine

Bind-mount /var/run/docker.sock into Jenkins on Linux, or mount the Docker Engine named pipe on Windows. section 11.2

Treat this mount as highly privileged: the container gains full access to Docker features on the host. Use it only with trusted images. section 11.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains the CLI-to-API channel, bind mounting, platform variants, practical uses, and host-access security risk.
Examples
Uses Jenkins Compose configurations that mount /var/run/docker.sock on Linux or the Docker Engine named pipe on Windows.
What it assumes
Assumes familiarity with containers, Docker CLI commands, Docker Compose, and Jenkins while clarifying the API connection from first principles.
What you can do after
Operate/configure Docker-backed CI by binding the local API channel into a Jenkins container and checking its security implications.
How it connects
Links Docker CLI, Docker API, Docker Engine, bind mounts, Docker Compose, Jenkins, containers, and Windows named pipes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.