Docker List Networks

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

In this guide, we'll explore the art of listing Docker networks with examples.

Why List Docker Networks? 

Listing Docker networks becomes crucial for several reasons: 

Verification: To ensure a newly created network is up and running. 

Clean-Up: To identify and remove any unnecessary or unused networks. 

Configuration Check: To inspect the details of specific networks. 

Troubleshooting: Helps in diagnosing connection or configuration issues. 

Listing Docker Networks 

To list all the Docker networks on your host, simply run:

docker network ls

When you run this command, the output will look something like this:

NETWORK ID NAME DRIVER SCOPE 16fa3b677b63 bridge bridge local 292f1b95f4fa host host local adcf8fc67a2d none null local

Understanding the Output:

NETWORK ID: A unique identifier for the network. 

NAME: The name of the network. 

DRIVER: The network driver being used. 

SCOPE: Specifies the scope of the network, which could be local, global, or swarm.

Default Networks

When you install Docker, it automatically creates three default networks. You can see them in the list above: 

bridge: The default network that a container gets attached to if no network is specified. It's a private internal network on your host, and containers get an internal IP from it. 

host: Removes network isolation between the container and the Docker host. Use with caution! 

none: A container-specific network stack. No external or internal communication is allowed unless explicitly configured.

Creating and Listing Custom Networks

You can create your custom network using the docker network create command. For instance:

docker network create my_custom_network

After creation, running docker network ls will now also show:

$ docker network ls .... c90f3b345e7f my_custom_network bridge local

Docker Network Filtering

Filtering by Network Name:

If you're looking for a network named "my_custom_network":

$ docker network ls --filter=name=my_custom_network NETWORK ID NAME DRIVER SCOPE 1a2b3c4d5e my_custom_network bridge local

Filtering by Network ID:

Let's say you have a specific network ID (e.g., "1a2b3c4d5e"):
$ docker network ls --filter=id=1a2b3c4d5e NETWORK ID NAME DRIVER SCOPE 1a2b3c4d5e some_network bridge local

Filtering by Network Driver:

To fetch all networks using the "bridge" driver:
$ docker network ls --filter=driver=bridge NETWORK ID NAME DRIVER SCOPE 1a2b3c4d5e network1 bridge local 6f7g8h9i0j network2 bridge local

Displaying Network IDs Only

To list only the IDs of the Docker networks:

docker network ls --format '{{.ID}}'

For example:

$ docker network ls --format '{{.ID}}' 2f259bab6f03 578a065dfead c678f4a8f8d5

Conclusion

In this guide, we have learned how to list default Docker networks, how to filter docker networks, and how to create and list custom Docker networks with examples.

Related Networking Guides

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare