Skip to content

Instantly share code, notes, and snippets.

@ianphil
Created June 23, 2016 20:03
Show Gist options
  • Save ianphil/7ffd23cb59bc2b187a86473c95f91cbd to your computer and use it in GitHub Desktop.
Save ianphil/7ffd23cb59bc2b187a86473c95f91cbd to your computer and use it in GitHub Desktop.
I was in meetings all day and used that time to learn a little about Docker Networks.
#
# Learn About Docker Networks
# github/tripdubroot
# Docker version 1.12.0-rc2
# build 906eacd
# experimental
#
# https://docs.docker.com/engine/userguide/networking/dockernetworks/#docker-embedded-dns-server
# https://docs.docker.com/engine/userguide/networking/configure-dns/
# https://github.com/docker/libnetwork/blob/ed311d050fda7821f2e7c53a7e08a0205923aef5/resolver.go
# Create a docker network to join containers to
docker network create tdrnet
# List all docker networks available
docker network ls
# List specific attributes about the network we created
docker network inspect tdrnet
# Create an Ubuntu container and join user-created network
docker run -itd --name tdrone --net=tdrnet ubuntu
# Create another ubuntu container and join the user-defined network
docker run -itd --name tdrtwo --net=tdrnet ubuntu
# List containers
docker ps
# List attributes of network, notice new endpoints created
docker network inspect tdrnet
# Enter the container to run commands:
docker attach tdrone
# Container Command: update cache and install network tools
apt-get update && apt-get install -y net-tools iputils-ping
# Container Command: look at eth settings
ifconfig
# Container Command: look at ip setting
cat /etc/hosts
# Container Command: look at nameserver setting
cat /etc/resolv.conf
# Container Command: ping other container by name
ping -c 4 tdrtwo
# Container Command: Exit container while leaving it running
(Ctrl + p + q)
# Stop running containes and remove
docker stop $(docker ps -q); docker rm $(docker ps -aq)
# Remove network
docker network rm tdrnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment