Last active
August 29, 2015 14:23
-
-
Save mbentley/008361909431d6fb39d7 to your computer and use it in GitHub Desktop.
docker + libnetwork (overlay) quickstart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install the kernel from utopic (on both nodes) | |
apt-get install -y linux-image-generic-lts-utopic | |
reboot | |
# install experimental docker release (on both nodes) | |
wget -qO- https://experimental.docker.com/ | sh | |
# install consul (on both nodes) | |
curl -OL https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip | |
apt-get install -y unzip | |
unzip 0.5.2_linux_amd64.zip | |
rm 0.5.2_linux_amd64.zip | |
mv consul /usr/local/bin/ | |
# start consul on node-1 | |
consul agent -server -bootstrap -data-dir /tmp/consul -bind=$(ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') > /var/log/consul.log 2>&1 & | |
# start consul on node-2 | |
consul agent -data-dir /tmp/consul -bind=$(ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') > /var/log/consul.log 2>&1 & | |
# join node-2 to node-1 | |
consul join <ip address of node-1> | |
# configure docker daemon on node-1 with these additional options: | |
--kv-store=consul:localhost:8500 --label=com.docker.network.driver.overlay.bind_interface=eth0 | |
# configure docker daemon on node-2 | |
--kv-store=consul:localhost:8500 --label=com.docker.network.driver.overlay.bind_interface=eth0 --label=com.docker.network.driver.overlay.neighbor_ip=<host-1-ip-address> | |
### example 1 (ping) | |
# start container on node-1 attached to network | |
docker run -it --publish-service=svc1.dev.overlay debian:jessie | |
# start container on node-2 attached to network | |
docker run -it --publish-service=svc2.dev.overlay debian:jessie | |
# ping svc1 from svc2 from inside the container on node-2 | |
ping svc1 | |
### example 2 (multi-container app) | |
# start postgres on node-1 attached to network | |
docker run -it --rm -p 5432 --publish-service=postgres.dev.overlay -e POSTGRES_USER=demo -e POSTGRES_PASSWORD=demo postgres:latest | |
# start docker-demo app on node-2 | |
docker run -it --rm -p 8080:8080 --publish-service=web.dev.overlay ehazlett/docker-demo-pg:latest -db-host="postgres" -db-name="demo" -db-pass="demo" -db-port=5432 -db-ssl="disable" -db-user="demo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment