Docker networks

Intermediate Docker

Mike Metzger

Data Engineering Consultant

Docker networking

  • Docker has extensive networking options
  • Can create networks to communicate between containers, host, and external systems
  • Will cover various commands to interact with networks.
Intermediate Docker

Docker networking types

  • Docker supports different networking types, using drivers
    • bridge: Default driver, allows connections out, connections in if exposed
    • host: Allows full communication between host and containers
    • none: Isolate container from network communications
    • Many others, including custom drivers
  • Will mostly use the bridge driver to create our own networks
Intermediate Docker

Working with Docker networks

Several commands:

  • docker network
    • docker network <command>
    • docker network <command> --help
    • docker network ls to list all docker networks on the host
    • docker network create to create a network
    • docker network rm to remove a network
Intermediate Docker

Docker network example

  • Create a Docker network named mynetwork
    repl@host:~$ docker network create mynetwork
    
5ff0febab98f73b74dd753eb44a30f7d7291052b3b1d58b0134589221cb8e33d
repl@host:~$ docker network ls

NETWORK ID NAME DRIVER SCOPE 2edc5ae4838c bridge bridge local a92988382711 host host local 5ff0febab98f mynetwork bridge local 5464ed866dad none null local
Intermediate Docker

Attaching containers to networks

  • How to connect container to a network?
  • docker run --network <networkname> ...
  • docker run --network mynetwork ubuntu bash
  • Can also connect containers later
    • docker network connect <networkname> <container>
    • docker network connect mynetwork ubuntu-B
Intermediate Docker

docker network inspect

  • How to check details of network?
  • docker network inspect <networkname>
  • Provides configuration info and IP addresses assigned to containers
    repl@host:~$ docker network inspect mynetwork
    
Intermediate Docker

docker network inspect example

        "Name": "mynetwork",
        ...
        "Driver": "bridge",
        ...
        Containers": {    "2be08aa942029191350d4bceb8816254af8713dd6f7dcbadcab8f068f7dbfdfa": {
                "Name": "unruffled_kare",
                "EndpointID": "29739356ae200e1e901d2eabef05efaca0fb37e1a4e1a4c3bf369f2892ca6c4b",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
Intermediate Docker

Let's practice!

Intermediate Docker

Preparing Video For Download...