# Docker Networking Guide for Developers

In our Docker journey so far, we’ve built and run containers for everything from Express applications to lightweight BusyBox shells. But one thing we haven’t really explored in detail is this: **how do Docker containers actually connect to the internet or to each other?**

In this blog, we'll break down Docker networking in a developer-friendly way.

Let’s dive in.

## 🧪 Does My Container Have Internet Access?

Let’s find out the answer by actually doing it. We'll run a BusyBox container and try to ping Google:

```bash
docker run --rm -it busybox sh
```

Once inside the container:

```bash
ping google.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752576013316/f29e7f49-5f8e-4a2a-8ab9-a4a1d52c5ceb.png align="center")

Boom! We get a response. That means our container has internet access ✅

This is made possible by Docker's **default bridge network**.

## 🧠 What is the Bridge Network?

By default, Docker assigns containers to a `bridge` network. This creates a **virtual Ethernet interface (veth)** on your host machine, and your container connects through it like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752579272735/3011cd65-02e7-47ce-bd11-53f67fa56219.png align="center")

Run this command to view it:

```bash
ifconfig
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752576090299/4ce21bef-a524-414b-8de9-8afc560726dd.png align="center")

You’ll see interfaces like `eth0` or `docker0` — that’s your container being connected to the host’s network via Docker’s bridge.

## ⚙️ Docker Networking Types (with Cheat Sheet)

Docker supports different **network drivers**. Here’s a quick summary:

| Driver | Use Case |
| --- | --- |
| **bridge (default)** | Containers on the same host can communicate and external access needs port mapping |
| **host** | The container shares the host's networking namespace (No isolation). |
| **none** | No network connectivity *(Fully isolated)*. |
| **overlay** | Enable multiple-host networking for swarm services. |
| **macvlan** | Assigns a real MAC address to the container *(acts like a physical device)*. |

## 🛠️ Essential Docker Network Commands

Let’s get hands-on. These are the commands you’ll use often:

### 🔍 List all networks

```bash
docker network ls
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752568432808/b45e7afb-ee72-4de7-ad99-04035db8a38a.png align="center")

### 🔎 Inspect a specific network

```bash
docker network inspect <network_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752568625950/e127af5a-a6f5-4457-b07a-1996bd649cfb.png align="center")

### 🧱 Create a custom bridge network

```bash
docker network create <network_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752568761953/82bf4aef-921d-4375-b366-b7487943269c.png align="center")

### 🚀 Run a container in a custom network

```bash
docker run --network <network_name> --name <container_name> -d <image_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752569112826/a7e7263d-8c5d-4574-aea2-c632bb1c8de2.png align="center")

### 🔗 Connect an existing container to a network

```bash
docker network connect <network_name> <container_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752570341054/97177d11-d0d6-4974-8436-1da1140d4368.png align="center")

### 🧼 Disconnect a container from a network

```bash
docker network disconnect <network_name> <container_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752570201035/a1c26b71-24f7-4034-b608-62109b6ac902.png align="center")

### 🗑️ Remove a network

```bash
docker network rm <network_name>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752570439736/24d40bf3-1416-4011-b955-1f5ceb2c567d.png align="center")

## 🤝 Container-to-Container Communication

Let’s try it out!

```bash
# Create custom bridge network
docker network create my-bridge-network
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752574005059/306c63b7-4fcc-4c75-8e29-15f7e31e7858.png align="center")

```bash
# Start container 1 using nginx
docker run -d --name container1 --network my-bridge-network nginx
```

Then check if container 1 is up and running:

```bash
docker ps
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752574144780/720ae565-37bf-461c-9140-dc7fe496edf5.png align="center")

```bash
# Start container 2 using alpine (lightweight Linux)
docker run -d --name container2 --network my-bridge-network alpine sleep 3600
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752574266956/21934c88-00bb-4ea2-b992-dcce242e27a0.png align="center")

```bash
# From container2, ping container1 using container name
docker exec -it container2 ping container1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752574413960/3ca59713-016c-4e8f-b7d5-7f5b2bd71791.png align="center")

If you're using Docker's default bridge, container names won’t resolve—only IPs work. But in custom bridge networks, Docker gives you automatic DNS resolution. 🎉

## 🖥️ Host Networking Example

```bash
docker run -d --network host nginx
```

This container now shares your host machine’s IP address. It’s faster and leaner, but there’s no isolation — use with caution!

## 🔐 MacVLAN Networking (Assigning Real MAC + IP)

Want your container to appear like a physical device on the network?

```bash
docker network create -d macvlan I am running a few minutes late; my previous meeting is running over.
  --subnet=192.168.1.0/24 \
  --gateway=192.168.1.1 \
  -o parent=eth0 \
  my-macvlan
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752575373603/1936a7a1-36d5-418c-96bf-3be8912aea88.png align="center")

This sets up a network where containers have their own MAC address and can appear directly on your LAN. Great for advanced setups or legacy systems that require MAC-level identity.

## 📚 Don't Memorize, Understand

Remember, it's not about memorizing every Docker command. It's about understanding the **structure** of commands:

```javascript
docker network <action> [options]
```

For example:

* `docker network ls`
    
* `docker network create <nework_name>`
    
* `docker network inspect <network_name>`
    
* `docker network connect <nework_name> <container_name>`
    

They're all intuitive once you get the hang of it.

## 📝 Summary

Docker networking isn’t as scary as it looks. Just remember:

* **Bridge** is the default.
    
* **Custom bridge** gives DNS resolution.
    
* **Host** removes isolation (be careful).
    
* **None** means no network.
    
* **Macvlan** makes your container feel like a physical device.
    

And most of all: **don’t overthink it**. For 95% of developer use cases, custom bridge networks with simple port mappings are more than enough.

If you found this helpful, please share it with your fellow developers.

Thanks for reading! 🙌

Happy learning! 🐳
