Orchestrating multiple dockers with Swarm

  • Introduction to Docker-Swarm.
  • Need of Docker-Swarm.
  • Strong Competitor to Swarm.
  • Docker Virtual Private Network.
  • High Availability with Docker Swarm.
  • Launching Docker Swarm at local host.
  • Demonstrating Docker Swarm with Playground(https://labs.play-with-docker.com)
  • Launching multiple docker-instances, using swarm, inside docker playground.
  • It can enable us to run our containers on a cluster.
  • it can help us to perform redeployments with zero downtime.
  • It’s an orchestration system and that means that all that can manage our containers in production.
  • Docker does actually contain its own built-In orchestration system, this thing called Docker-Swarm.
  • We have a database service.
  • We also have a kind of Java container running a spring boot application.
  • Of course, two containers would be absolutely fine to run on a single physical computer, but once we start scaling up to dozens or hundreds of containers, then you’d probably struggle to find a server that can cope. You would certainly need a very, very expensive server to run so many containers.
  • So it’s very common to scale horizontally, which means to distribute the containers across multiple physical computers.
  • Rather than running on a single host computer, we’re going to distribute across multiple so-called nodes. For example, we might have four nodes open.
  • So, now we’ve been on a single hosted system and we’ve been running commands such as Docker Container Run. The big difference in a swarm is that we’ll log on to one of these nodes and we’re going to issue commands to docker swarm.
docker swarm init
docker swarm join --token <TOKEN_RECEIVED_FROM_SWARM-MANAGER>
docker network create --driver overlay aditya-overlay-network
docker network ls
docker container run -v /Users/B0218162/Documents/LEARNINGS/MEDIUM-BLOG/Docker/DOCKER_LEARN/DATA_DIR_FOR_CONTAINER:/var/lib/mysql -d -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=fleetman --network aditya-network --name mysqldbpanga mysql:5
docker service create -d --network aditya-overlay-network -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=fleetman --name mysqldbpangavari mysql:5
  • Note here that, we have specified the name of our (to be launched) container as : “mysqldbpangavari”.
  • We are passing an intent to swarm that, container should be launched with a docker-image “mysql” with version as 5.
  • We also specified the network, while launching the container through the Swarm (Service). Here, we have used the overlay-network, the one that we launched above.
  • We also specified the TWO environment variables while launching the service with docker swarm i.e. password & database_name.
docker service ls
docker container ls
docker swarm init --advertise-addr <eth0_ip_address>
docker swarm join --token <TOKEN_ID> <IP_WHERE_SWARM_WAS_INITALISED>
docker network create --driver overlay <NAME_OF_NETWORK>
docker network ls
docker service create -d --network <NAME_OF_NETWORK> -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=fleetman --name database mysql:5
docker service ls
  • Above first output shows us that, currently there are no instances of this container running. But we require one instance.The reason for that is the container will be starting up in the background.
  • Once that container started will that switch to a ONE/ONE. So, that means somewhere in our swarm, there is a container running for the database.
docker container ls
  • In our case, the container powering to mysql, has been launched @ the Node1 only, but it can be very much possible that, this particular instance could had been launched @ another node(i.e. other nodes which are part of Swarm) as well.
  • Now, say, if we launch another instance as well (i.e. as a swarm-service), then the same would be surely launched on the other instance, because swarm automatically balances the load and would make sure that, each node has 1 container running there.
docker container logs -f <NAME_OF_CONTAINER>
docker node ls
docker node ls



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aditya goel

aditya goel

Software Engineer for Big Data distributed systems