Docker Swarm installation Guide How to Install and Configure Docker Swarm on Ubuntu 16.04 Step1: update the necessary packages for ubuntu Step2: Install the below packages to ensure the apt work with https method, and that CA certificates are installed. Step 3: Add the GPG key for Docker repository on your system. Step4: Now, add the official Docker repository by running the following command in the terminal. echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" sudo tee -a /etc/apt/sources.list.d/docker.list Step 5: Update the apt database. Step 6: Make sure you are installing the docker from the official repository, not from the default Ubuntu 16.04 / 14.04 repo. Install Docker on Ubuntu Now, install the Docker using the following command. Step 7: Docker installation in command line
Step 8 : Docker starting and enable docker while boot. Step 9: Run a docker container to verify the Docker installation Step 10: Allow Non-root user to run Docker By default, you would require root privilege to run docker commands. To avoid this, I had been using docker commands with sudo. If you want to allow non-root users to run Docker containers, follow the below steps to give them privileges to run a Docker. Create a group called docker if it does not exist. Step 11 : Add a user to docker group. Step 12 : Log out and log back in. Now, you should now be able to run Docker commands without prefixing sudo.
Step 13: Firewall You would need to open following ports on the firewall for a swarm cluster to work properly. Restart the Docker engine after you have opened up the required ports as the firewall chain does affect the docker rules.
Create a Swarm Let s initiate a cluster creation using swarm init. Run the following command on your manager node advertise-addr option specifies the manager node to publish its address as 192.168.1.144 so that worker node can join the cluster. The above output has the token to add worker nodes to the cluster. View the current status of the swarm using the following command. You can list down the Docker nodes in the swarm with the following command. Adding Nodes to a Swarm Cluster
If you remember the output of swarm init command we ran on the manager, the output has the token to add nodes to the cluster. Just go back to that output and copy it, then paste that on the worker nodes. Node 1: Node 2: do same for second node also On Docker manager, run the docker node ls command to list down the worker nodes. Launching service in Docker Swarm mode Now, the Docker Swarm is up and running. Let s test a swarm by deploying service on it. Here, we will run a service called web with the image of httpd. Run the following command on the Docker manager. If you specify replicas <unit>, docker swarm will create unit number of tasks (or containers) of the same image for the specified service across the Docker worker nodes. To know which services are running on a cluster and how many replicas are there. To find on which node the service is running on by using the following command.
In our example, the service web is running on node2.itzgeek.local. Since we are running a web service, you can verify the service by pointing your browser to http://node1.dockerworker or http://192.168.1.123 You should get the following page. Scale up and Scale down service in the swarm In Docker swarm, we can scale up or down a service by creating additional instances. As you know, currently we have only one container for service web running on Docker manager. To test the scalability, let s scale the service web to five instance. Check where your instances are started. In some cases, we may likely to scale down.
High Availability or Container Self-Healing just stop the Docker service running on any one of the worker nodes. For Ex, I m stopping the Docker service on node1.workersnode ------------------------------- Done by somappa Srinivasan-----------------------------------------------