• Networking background
  • Creating Docker container networks
  • Network-less and host-mode containers
  • Publishing services on the ingress network
  • Container network caveats

    5.1 Networking background( for beginners)

    5.1.1 Basics: Protocols, interfaces, and ports

    5.1.2 Bigger picture: Networks, NAT, and port forwarding

    5.2 Docker container networking

    1. docker network ls

    image.png

    5.2.1 Creating a user-defined bridge network

    Build a new network with a single command:

    1. docker network create \
    2. --driver bridge \
    3. --label project=dockerinaction \
    4. --label chapter=5 \
    5. --attachable \
    6. --scope local \
    7. --subnet 10.0.42.0/24 \
    8. --ip-range 10.0.42.128/25 \
    9. user-network

    5.2.2 Exploring a bridge network

    start exploring your new bridge network by creating a new container attached to that network:

    1. docker run -it \
    2. --network user-network \
    3. --name network-explorer \
    4. alpine:3.8 \
    5. sh

    image.png

    1. docker network create \
    2. --driver bridge \
    3. --label project=dockerinaction \
    4. --label chapter=5 \
    5. --attachable \
    6. --scope local \
    7. --subnet 10.0.43.0/24 \
    8. --ip-range 10.0.43.128/25 \
    9. user-network2
    1. docker network connect \
    2. user-network2 \
    3. network-explorer
    1. docker attach network-explorer

    image.png

    5.3 Special container networks: host and null

    1. docker run --rm \
    2. --network host \
    3. alpine:3.8 ip -o addr
    1. docker run --rm \
    2. --network none \
    3. alpine:3.8 ip -o addr

    5.4 Handling inbound traffic with NodePort publishing

    1. docker run --rm \
    2. -p 8080 \
    3. alpine:3.8 echo "forward ephemeral TCP -> container TCP 8080"
    4. docker run --rm \
    5. -p 8088:8080/udp \
    6. alpine:3.8 echo "host UDP 8088 -> container UDP 8080"
    7. docker run --rm \
    8. -p 127.0.0.1:8080:8080/tcp \
    9. -p 127.0.0.1:3000:3000/tcp \
    10. alpine:3.8 echo "forward multiple TCP ports from localhost"

    5.5 Container networking caveats and customizations

    5.5.1 No firewalls or network policies

    5.5.2 Custom DNS configuration

    1. docker run --rm \
    2. --hostname barker \
    3. alpine:3.8 \
    4. nslookup barker

    5.5.3 Externalizing network management