JA
header image

枝折 - bookmark

Docker Network Drivers

Container

CREATED: 2026 / 04 / 29 Wed

UPDATED: 2026 / 04 / 29 Wed

An overview of Docker network drivers (bridge / host / none)

Docker Network Drivers

Docker uses “network drivers” to manage container network connectivity. The choice of driver determines how containers communicate with the host and other containers. Here we focus on bridge, host, and none.

bridge

bridge is Docker’s default network driver. If you don’t specify --network when starting a container, it automatically connects to the bridge network.

In a bridge network, a private virtual network is created on the host, and containers connect to it. Containers can communicate using IP addresses, and when using a user-defined bridge network, they can also communicate by container name.

Bridge networks also support dynamic port mapping, allowing the container’s port to remain fixed while the host port is assigned randomly. This makes it possible to run multiple containers using the same port simultaneously on the same host.

Default Bridge vs. User-Defined Bridge

When Docker starts, a default bridge network is created. Separately, user-defined bridge networks can be created with docker network create.

The biggest difference between them is name resolution. User-defined bridges support automatic DNS resolution by container name — containers on the same network can be reached by container name. The default bridge does not support this DNS resolution; to use container names, the --link option was required (now deprecated).

Name Resolution on Bridge Networks

As mentioned, user-defined bridges automatically enable name resolution by container name:

# Create a user-defined bridge network
docker network create my-network

# Start containers and connect them to the network
docker run -d --name app --network my-network my-app-image
docker run -d --name db --network my-network postgres

With this setup, from within the app container you can connect to the database by using the name db. Since container IP addresses can change on restart, using container names to identify communication targets avoids hardcoding IPs.

The --link option enabled container-name communication on the default bridge too, but when name resolution is needed, simply use a user-defined bridge.

Bridge Network and L2 Switch

Docker’s bridge network is implemented internally as a Linux virtual bridge (default: docker0). This virtual bridge acts as an L2 switch.

An L2 switch is a network device that operates at the data link layer (L2) of the OSI model and makes forwarding decisions based on MAC addresses.

In Docker, each container is assigned a veth pair (virtual Ethernet interface), which connects the container’s eth0 to the host’s docker0 bridge. Communication between containers on the same bridge network is forwarded at the L2 level by docker0 based on MAC addresses.

Container A (eth0) <--veth--> [docker0 (L2 bridge)] <--veth--> Container B (eth0)

Communication between different networks involves iptables routing (L3), but within the same bridge, packet forwarding is handled by the L2 switch.

host

With the host driver, the container shares the host’s network. In other words, the container and host share the same network namespace.

docker run --network host nginx

Running this, nginx accepts connections directly on the host’s port 80 without any port mapping (-p). Starting another server on port 80 on the same host while this is running will cause a conflict.

none

none does exactly what the name suggests — the container has no network interfaces at all.

docker run --network none alpine

The container is completely network-isolated. This is useful for batch processes that don’t need network access, or when you want to prevent all external communication for security reasons.

Network Configuration in Docker Compose

When using Docker Compose, a user-defined bridge network is automatically created per project. Services defined in the same docker-compose.yml can communicate with each other by service name without any additional configuration:

services:
  app:
    build: .
    ports:
      - '3000:3000'
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: password

In this case, the app service can connect to the database using db as the hostname. Each service name automatically becomes its hostname.

You can also define networks explicitly:

services:
  app:
    build: .
    ports:
      - '3000:3000'
    networks:
      - frontend
      - backend
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: password
    networks:
      - backend
  nginx:
    image: nginx:alpine
    ports:
      - '80:80'
    networks:
      - frontend

networks:
  frontend:
  backend:

With this setup, multiple networks are defined and each service connects to specific ones. app is on both frontend and backend, while db is only on backend — so nginx cannot communicate directly with db.

Appendix

Bonus: Amazon ECS Network Modes

When launching ECS tasks, you also specify a network mode. ECS task definitions support bridge, host, awsvpc, and none as networkMode options.

bridge, host, and none are only available for ECS on EC2. awsvpc works with both EC2 and Fargate and is the AWS-recommended mode.

awsvpc

Each task is assigned an ENI (Elastic Network Interface), with a private IP address and DNS name within the VPC. Tasks can have the same level of network configuration as EC2 instances, enabling fine-grained access control at the task level via Security Groups. Since Fargate only supports awsvpc, it is effectively the standard mode.

bridge

Uses the same mechanism as Docker’s bridge network, with containers communicating through the virtual network (docker0) on the EC2 instance. When multiple tasks need to use the same port, dynamic port mapping (random host port assignment) handles this. The overhead of routing through docker0 makes it slightly less performant than host or awsvpc.

host

Containers use the host EC2 instance’s network stack directly. Like Docker’s host driver, container ports map directly to the EC2 instance’s ENI. With bridge, docker0 can handle dynamic port mapping to run multiple containers on the same port on one host — host mode cannot do this. In host mode, hostPort must be explicitly specified in the task definition, making dynamic port mapping impossible. This means running multiple instances of the same task on the same host will cause port conflicts, making scale-out difficult.

none

ECS also supports a network-isolated mode for tasks that require no external connectivity — suitable for batch processing and similar workloads.

References: