Skip to content

Access Docker Via Remote APIs

When automating deployments (e.g., Jenkins CI/CD), you need scripts to talk to the Docker Engine remotely. The Docker daemon listens for API requests via three socket types: UNIX, TCP, and FD.

  • UNIX Socket (Default): /var/run/docker.sock. Used for local communication. Requires root or docker group membership.
  • TCP Socket (Remote): Can be opened on port 2375 (unencrypted) or 2376 (encrypted/HTTPS).

Configuration Conflicts: If you try to configure the Docker daemon to listen to a TCP port in two different places simultaneously, Docker will crash and fail to start.

  1. Systemd Service File (/usr/lib/systemd/system/docker.service): Defines the startup flags (e.g., ExecStart=/usr/bin/dockerd -H unix://).
  2. Daemon JSON (/etc/docker/daemon.json): Defines hosts explicitly (e.g., "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]). You must choose only ONE method to configure the daemon bindings.

cURL Mapping to Docker CLI: Once the TCP socket is exposed (e.g., on IP 192.168.56.15:2375), you can interact with it via standard HTTP REST calls:

  • curl 192.168.56.15:2375/info ↔ Maps to docker info
  • curl 192.168.56.15:2375/images/json ↔ Maps to docker images
  • curl 192.168.56.15:2375/containers/json ↔ Maps to docker ps
  • curl 192.168.56.15:2375/containers/json?all=1 ↔ Maps to docker ps -a