0Pricing
Docker & DevOps Fundamentals · Lesson

Container Networking Basics

Understand Docker's default networking, bridge networks, and how containers find each other.

Container Networking Basics is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Container Networking?

Containers are isolated by design, which is great for security and portability. However, for applications to be useful, they often need to communicate with each other and the outside world.

This is where Docker networking comes in! It allows containers to talk securely and efficiently.

Container Networking Basics — illustration 1

Docker's Default Bridge Network

When you run a container without specifying a network, Docker automatically connects it to the default bridge network. This network is named bridge.

Containers on this network can communicate with each other using their IP addresses, and they also get access to the internet.

Inspecting Docker Networks

You can easily see all the Docker networks available on your system. The docker network ls command lists them, and docker network inspect provides detailed configuration for a specific network.

Try listing your networks:

docker network ls

Container IP Addresses

Each container connected to a bridge network (default or user-defined) is assigned its own unique IP address by Docker's internal DNS server.

This IP address allows other containers on the same network to reach it. Let's see a container's IP:

docker run --rm -it alpine ip a

Communication on Default Bridge

On the default bridge network, containers can communicate with each other using their assigned IP addresses. However, IP addresses can change, making this method less reliable for dynamic applications.

For better container discovery and communication by name, user-defined bridge networks are the modern and preferred approach.

User-Defined Bridge Networks

User-defined bridge networks offer significant advantages over the default bridge:

  • Automatic DNS Resolution: Containers on the same user-defined network can find each other by their service name (the container name).
  • Better Isolation: They provide better isolation for your applications.
  • Configurability: You have more control over network settings.

Demo: Communicate by Name

Let's create a custom network, run an Nginx web server on it, and then use another container to access the Nginx server by its name. Watch how easy it is!

docker network create my-app-net
docker run -d --name webserver --network my-app-net nginx
docker run --rm --network my-app-net alpine sh -c "apk add curl && curl -s http://webserver"
docker rm -f webserver
docker network rm my-app-net

Exposing Ports to Host

To access a container's service from your host machine or an external network, you need to 'publish' or 'map' its port using the -p or --publish flag.

For example, -p 8080:80 maps host port 8080 to container port 80.

docker run -d --name my-webserver -p 8080:80 nginx
# To check, open http://localhost:8080 in your browser
# Then, clean up the container:
docker rm -f my-webserver

Other Network Drivers

Beyond bridge networks, Docker offers other network drivers for specific use cases:

  • Host: The container shares the host's network stack, losing isolation.
  • None: The container has no network interfaces.
  • Overlay: Used for Docker Swarm to enable communication across multiple Docker daemons on different hosts.

Each driver serves a unique purpose in different deployment scenarios.

Networking Challenge

Which statements about Docker's default bridge network and user-defined bridge networks are true?

Recap: Networking Basics

We've covered the essentials of Docker networking:

  • The default bridge network allows containers to communicate by IP.
  • User-defined bridge networks are preferred for automatic DNS resolution by name and better isolation.
  • We learned how to make containers talk to each other and how to expose container ports to the host.
  • Briefly touched on other network drivers like host and overlay.

Understanding networking is crucial for building interconnected containerized applications. Next, we'll dive into managing persistent data with Docker Volumes!

Frequently asked questions

Is the “Container Networking Basics” lesson free?

Yes — the full text of “Container Networking Basics” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Container Networking Basics”?

Understand Docker's default networking, bridge networks, and how containers find each other. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Docker & DevOps Fundamentals?

No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Container Networking Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Docker & DevOps Fundamentals lesson?

Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Container Networking Basics
  2. Docker Volumes for Persistence
  3. Bind Mounts and tmpfs Mounts
  4. Custom Bridge Networks and Service Discovery
← Back to Docker & DevOps Fundamentals