2.1.3.1 Container API Routes
A focused guide to Container API Routes, connecting core concepts with practical Docker and container operations.
Container API routes are the set of HTTP endpoints, under the /containers path, that the Docker daemon exposes for creating, listing, inspecting, starting, stopping, and removing containers — the underlying mechanism behind every CLI command related to container lifecycle management.
Listing Containers
The most frequently used route lists containers currently known to the daemon, optionally including stopped ones.
curl --unix-socket /var/run/docker.sock "http://localhost/containers/json?all=true"
This returns the same information docker ps -a displays, in raw JSON form rather than a formatted table.
Creating and Starting a Container
Creating a container and starting it are distinct API operations, mirroring the distinction between docker create and docker start at the CLI level.
curl --unix-socket /var/run/docker.sock -X POST http://localhost/containers/create \
-H "Content-Type: application/json" \
-d '{"Image":"nginx","name":"myapp"}'
curl --unix-socket /var/run/docker.sock -X POST http://localhost/containers/myapp/start
Inspecting a Specific Container
A dedicated route returns detailed configuration and runtime state for a single container, identified by its name or ID.
curl --unix-socket /var/run/docker.sock http://localhost/containers/myapp/json
This is the data source behind docker inspect, returning everything from the container's network settings to its current process status.
Stopping and Removing Containers
Separate routes handle stopping a running container gracefully and removing a container's record entirely once it is no longer needed.
curl --unix-socket /var/run/docker.sock -X POST http://localhost/containers/myapp/stop
curl --unix-socket /var/run/docker.sock -X DELETE http://localhost/containers/myapp
Streaming Logs and Stats
Routes for logs and live resource statistics keep their connections open, streaming data as the container produces it, rather than returning a fixed snapshot.
curl --unix-socket /var/run/docker.sock "http://localhost/containers/myapp/stats?stream=true"
Why These Routes Matter
Every container-related CLI command is, underneath, a call to one of these routes — understanding the routes directly is useful when building tooling that needs to manage containers programmatically without relying on parsing CLI output.