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
