Network API Routes
Network API Routes define how Docker containers communicate over networks, enabling services to interact securely and efficiently within and across environments
Network API routes are the set of HTTP endpoints, under the /networks path, that the Docker daemon exposes for creating, listing, inspecting, connecting containers to, and removing the virtual networks containers use to communicate.
Listing Networks
A route returns every network currently defined on the daemon, including the default networks Docker creates automatically and any user-defined networks.
curl --unix-socket /var/run/docker.sock http://localhost/networks
This corresponds to what docker network ls displays as a formatted table.
Creating a Network
Creating a network specifies its name and driver (such as bridge for single-host networking or overlay for multi-host networking in a Swarm).
curl --unix-socket /var/run/docker.sock -X POST http://localhost/networks/create \
-H "Content-Type: application/json" \
-d '{"Name":"myapp-net","Driver":"bridge"}'
Connecting and Disconnecting Containers
Separate routes attach a running or stopped container to a network, or detach it, which can be done after a container has already started, not just at creation time.
curl --unix-socket /var/run/docker.sock -X POST http://localhost/networks/myapp-net/connect \
-H "Content-Type: application/json" \
-d '{"Container":"myapp"}'
Inspecting Network Membership
A dedicated route returns full details about a network, including which containers are currently attached to it and what IP addresses they have been assigned.
curl --unix-socket /var/run/docker.sock http://localhost/networks/myapp-net
This is the underlying data behind docker network inspect, useful for diagnosing why two containers can or cannot reach each other.
Removing a Network
A network can only be removed once no containers remain attached to it, the same constraint the CLI enforces when running docker network rm.
curl --unix-socket /var/run/docker.sock -X DELETE http://localhost/networks/myapp-net
Why These Routes Matter
Programmatically managing container networking — for example, dynamically attaching newly created containers to the correct network as part of an automated deployment process — depends directly on these routes, since they are the only interface through which network state can be changed.