2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

08/20/2016: Running PostgreSQL on Docker Swarm 1.12

For this example, I am using a five node Docker Swarm cluster running on VirtualBox. At this start, I assume the swarm is running and that the swarm master is called pi1.

NOTE: The name ‘pi1’ has no relevance. It can be anything. Just change the references to your name.

  • See the swarm running.
eval $(docker-machine env pi1)
docker node ls
  • Start the postgres service.
eval $(docker-machine env pi1)
docker service create \
  --env POSTGRES_DB=ckan \
  --env POSTGRES_USER=ckan \
  --env POSTGRES_PASSWORD=ckan \
  --publish 5432:5432 \
  --name postgres \
  postgres:9.5
  • Run a command-line client from outside of the swarm.
eval $(docker-machine env --unset)
docker run \
  --add-host postgres:$(docker-machine ip pi1) \
  --env PGPASSWORD=ckan \
  -it \
  --rm \
  postgres:9.5 \
  psql -h postgres -U ckan
  • Use the client.

Do whatever is needed at the postgres command-line and then type ‘\q’ to exit.

  • Stop the service.
eval $(docker-machine env pi1)
docker service rm postgres
eval $(docker-machine env --unset)

08/19/2016: Docker Swarm 1.12 on VirtualBox

This post shows the steps I followed to run Docker Swarm 1.12 on VirtualBox.

Start the cluster

docker-machine create --driver virtualbox pi1
docker-machine create --driver virtualbox pi2
docker-machine create --driver virtualbox pi3
docker-machine create --driver virtualbox pi4
docker-machine create --driver virtualbox pi5

List the IP Addresses

for i in `seq 1 5`; do
  echo "HOST: pi$i IP: $(docker-machine ip pi$i)";
done

Start Swarm Master

export SWARM_ID=$(docker-machine ssh pi1 docker swarm --advertise-addr=$(docker-machine ip pi1) init)

Start Agents

export SWARM_JOIN_CMD=$(docker-machine ssh pi1 docker swarm join-token worker | tail -n 4 | head -n 3 | tr --delete '\\')

for i in `seq 2 5`; do
  docker-machine ssh pi$i $SWARM_JOIN_CMD
done

L#ist swarm nodes

eval $(docker-machine env pi1)
docker node ls

Exercise the swarm

eval $(docker-machine env pi1)
docker service create --name ping alpine ping 8.8.8.8
docker service ps ping
docker service update --replicas 10 ping
docker service rm ping

Shutdown the cluster

eval $(docker-machine env --unset)
docker-machine env --unset
for i in `seq 0 5`; do
  docker-machine rm -y pi$i;
done