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. Requiresrootordockergroup membership. - TCP Socket (Remote): Can be opened on port
2375(unencrypted) or2376(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.
- Systemd Service File (
/usr/lib/systemd/system/docker.service): Defines the startup flags (e.g.,ExecStart=/usr/bin/dockerd -H unix://). - 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 todocker infocurl 192.168.56.15:2375/images/json↔ Maps todocker imagescurl 192.168.56.15:2375/containers/json↔ Maps todocker pscurl 192.168.56.15:2375/containers/json?all=1↔ Maps todocker ps -a