Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active August 5, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/d048216ab2495e0a9f53a95568fa90de to your computer and use it in GitHub Desktop.
Save npodonnell/d048216ab2495e0a9f53a95568fa90de to your computer and use it in GitHub Desktop.
Docker Networking Cheatsheet

Docker Networking Cheatsheet

N. P. O'Donnell, 2020

List networks:

docker network ls

Create a network called beatles:

docker network create beatles

Create and start 4 alpine containers in beatles network:

NAME=john; docker run -dit --network beatles --network-alias $NAME --name $NAME --hostname $NAME alpine /bin/sh
NAME=paul; docker run -dit --network beatles --network-alias $NAME --name $NAME --hostname $NAME alpine /bin/sh
NAME=george; docker run -dit --network beatles --network-alias $NAME --name $NAME --hostname $NAME alpine /bin/sh
NAME=ringo; docker run -dit --network beatles --network-alias $NAME --name $NAME --hostname $NAME alpine /bin/sh

Inspect network:

docker network inspect beatles

Attach to john, check hostname, ping paul:

$ docker attach john
/ # hostname
john
/ # ping paul
PING paul (172.20.0.3): 56 data bytes
64 bytes from 172.20.0.3: seq=0 ttl=64 time=0.152 ms
64 bytes from 172.20.0.3: seq=1 ttl=64 time=0.178 ms
^C
--- paul ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.152/0.165/0.178 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment