docker network ls

Docker networking gives containers a way to communicate with each other and with the outside world. The docker network ls command provides a quick view of the networks currently known by the Docker daemon. It is a read-only command, so it does not create, modify, or remove a network. Instead, it returns a list that helps users confirm network names, identifiers, drivers, and scopes before they move on to related actions.

Understanding the Default Output

Running docker network ls prints a table. By default, the table includes four columns:

  • NETWORK ID: The unique identifier for the network. Docker shows only the first 12 characters unless --no-trunc is used.
  • NAME: The network name, such as bridge, host, none, or a custom name.
  • DRIVER: The network driver, including bridge, host, null, overlay, or macvlan.
  • SCOPE: The network scope, usually local, or swarm in a Swarm setup.

Example:

docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
7fca4eb8c647   bridge    bridge    local
9f904ee27bf5   host      host      local
cf03ee007fb4   none      null      local

The default bridge network is often used for basic container communication. The host network allows a container to share the host network stack. The none network gives a container no normal network interface, only a loopback address.

Basic Syntax and Options

The command uses this syntax:

docker network ls [OPTIONS]

Common options include:

  • --filter, -f: Filter networks by condition.
  • --format: Use a Go template to control output.
  • --no-trunc: Show the complete network ID.
  • --quiet, -q: Output only network IDs.

These flags are helpful when users need a smaller result set or when they want to use the output in scripts.

Practical Examples

List all networks:

docker network ls

List only IDs:

docker network ls -q

Show full IDs:

docker network ls --no-trunc

Filter by driver:

docker network ls --filter driver=bridge

Filter by name:

docker network ls --filter name=app

Combine filters:

docker network ls --filter driver=bridge --filter name=app

Use custom format:

docker network ls --format "table {{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.Scope}}"

Available placeholders may include {{.ID}}, {{.Name}}, {{.Driver}}, {{.Scope}}, {{.IPv6}}, {{.Internal}}, and {{.Labels}}.

To print names only:

docker network ls --format "{{.Name}}"

Creating and Inspecting a Custom Network

The command is often used with docker network create. For instance, create a custom bridge network:

docker network create --driver bridge app-net

List it:

docker network ls --filter name=app-net

Run a container on it:

docker run -d --name web --network app-net nginx

Then inspect the network:

docker network inspect app-net

Troubleshooting and Cleanup

If containers cannot resolve each other by name, verify that they are on the same network. Use docker network ls and then docker network inspect.

If a name conflict appears, Docker Compose may add a project prefix. Filtering by the project name can help.

To clean up unused networks, list networks first, then run docker network prune.

When using a remote Docker context, docker network ls shows networks on the selected host.

Summary

docker network ls is a basic but important Docker command. It reveals network ID, name, driver, and scope. Through filters, formats, quiet mode, and full ID output, it supports both quick checks and automation. Combined with other network commands, it helps users manage Docker networking with greater confidence.