- Stop or delete running containers, impacting applications and users
- Remove volumes, causing irreversible data loss
- Launch malicious containers (e.g., crypto miners)
- Escalate to root on the host via privileged containers
/var/run/docker.sock) restricts access to local users. Before exposing the daemon over TCP, ensure your host follows standard hardening best practices:
- Disable direct root SSH logins
- Enforce SSH key–based authentication; disable passwords
- Close unused ports; restrict firewall rules
- Limit user accounts on the host
Exposing the Docker API Over TCP
To manage Docker remotely (from a CI server or management host), you can bind the daemon to a TCP endpoint. Edit/etc/docker/daemon.json and add a hosts entry:
Never expose
2375 (unencrypted) on a public interface. Always bind to a private network or VPN.Encrypting the Docker Remote API with TLS
Unencrypted TCP traffic can be intercepted. To enable TLS:- Create your own Certificate Authority (CA)
- Generate a server key (
server-key.pem) and certificate (server.pem) - Place them on the Docker host (e.g.,
/var/docker/)
/etc/docker/daemon.json:
Client Configuration for Encryption Only
On the client machine:This setup encrypts traffic but does not verify client identity. Anyone with
DOCKER_TLS=true and the host address can connect.Enabling Mutual TLS Authentication (mTLS)
To ensure only authorized clients connect, enable client cert verification:- Generate a client key (
client-key.pem) and certificate signing request (CSR). - Sign the CSR with your CA to create
client.pem. - Distribute
client.pem,client-key.pem, andcacert.pemto each client securely.
/etc/docker/daemon.json:
Client Usage with mTLS
Option 1: Place certificates in~/.docker/ and use environment variables:
By default, Docker looks in
~/.docker/ for ca.pem, cert.pem, and key.pem. Rename your files accordingly for automatic discovery.Security Modes Overview
| Mode | Encryption | Client Auth | Use Case |
|---|---|---|---|
| Default (Unix socket) | No | N/A | Local development |
| TCP without TLS | No | N/A | Not recommended |
| TLS only | Yes | No | Encrypt traffic |
Mutual TLS (tlsverify) | Yes | Yes | Production, CI/CD environments |