Networking

Docker Network Types

  1. Bridge Network (Default)

  • Used for communication between containers on the same host.

  • Created automatically when running containers.

  • Manually create: docker network create my_bridge_network

  • Docker Compose:

#yaml
networks:
  my_bridge_network:
    driver: bridge
  1. Host Network

  • Containers share the host’s network namespace (no isolation).

  • Manually create: docker network create -d host my_host_network

  • Docker Compose:

# yaml
networks:
  my_host_network:
    driver: host
  1. Overlay Network

  • Used in Swarm mode for multi-host communication.

  • Manually create: docker network create -d overlay my_overlay_network

  • Docker Compose:

  1. Macvlan Network

  • Assigns containers unique IPs on the local network.

  • Manually create: docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 my_macvlan_network

  • Docker Compose:

  1. None Network

  • Completely isolates the container (no networking).

  • Manually create: docker network create -d none my_none_network

  • Docker Compose:

Specify static ip address

Commands

  • docker network ls

  • docker network inspect $name

  • docker network connect $network $container: connect $container to $network

  • docker network create -d macvlan -o parent=enp86s0.4 vlan4_net: create network

  • docker network create -d macvlan --subnet=192.168.4.0/24 --gateway=192.168.4.1 -o parent=enp86s0.4 vlan4_net

Reference

Last updated