{ "cells": [ { "cell_type": "markdown", "id": "a144def9-291d-4eed-9812-f67ace178654", "metadata": {}, "source": [ "# Docker Swarm\n", "## Tutorial of docker swarm from the Docker Official Documentation\n", "\n", "The tutorial of docker swarm can be refered from the following [link](https://docs.docker.com/engine/swarm/swarm-tutorial/):\n", "\n", "It majorly covers:\n", "- [Get started with swarm mode](https://docs.docker.com/engine/swarm/swarm-tutorial/)\n", "- [Create a swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/)\n", "- [Add nodes to the swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/add-nodes/)\n", "- [Deploy a service](https://docs.docker.com/engine/swarm/swarm-tutorial/deploy-service/)\n", "- [Inspect the service](https://docs.docker.com/engine/swarm/swarm-tutorial/inspect-service/)\n", "- [Scale the service in the swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/scale-service/)\n", "- [Delete the service running on the swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/delete-service/)\n", "- [Apply rolling updates to a service](https://docs.docker.com/engine/swarm/swarm-tutorial/rolling-update/)\n", "- [Drain a node on the swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/drain-node/)\n", "\n", "One must understand the different docker command to create the swarm network, add the nodes to the swarm network, create the service, inspect the service, apply the rolling update, and to delete the service." ] }, { "cell_type": "markdown", "id": "3d035f25-f6d6-4e83-a428-09cfcece3039", "metadata": {}, "source": [ "## Create your own swarm cluster and Deploy app in Docker Swarm\n", "\n", "Here, we create our own swarm cluster and deploy the house rate prediction model in the docker swarm using the following steps. \n", "\n", "### Step-1: Create the swarm cluster using following command:\n", "\n", "```bash\n", " foo@bar:$ docker swarm init --advertise-addr \n", "\n", "```\n", "\n", "where `` is the IP address of your node machine. The above command will give the output as following:\n", "\n", "```bash\n", " Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.\n", " \n", " \n", " To add a worker to this swarm, run the following command:\n", " \n", " docker swarm join \\\n", " --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \\\n", " 192.168.99.100:2377\n", " \n", " To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n", "```\n", "\n", "### Step-2: Add the nodes as the managers and the workers\n", "The next step is to add the new nodes in the swarm network using the information obtained as a response in the above command. The `docker swarm join` command with the appropirate response information needs to be executed from the node moachine that needs to join the swarm network.\n", "\n", "### Step-3: Deploy the service for house rate prediction\n", "The next step is to deploy the docker service `house_rate_prediction_service` for house rate prediction using the docker image `house_rate_prediction_deploment` on the `port 5000` using the following command:\n", "\n", "```bash\n", " foo@bar:$ docker service create --replicas 1 --name house_rate_prediction_service -p 5000 house_rate_prediction_deploment\n", "\n", "```\n", "\n", "#### Output of docker service\n", "After, the successful convergence of the service, one may attemp to use the house rate prediction model which is deployed on the on the following link: `0.0.0.0:5000/`\n", "\n", "HTML form to get value from user\n", "\n", "![InputFromUSer](Images/Docker/Docker_Flask_WebPage.png)\n", "\n", "\n", "View displaying the house rate prediction to the user\n", "\n", "![Response](Images/Docker/Docker_Flask_Response.png)\n" ] }, { "cell_type": "markdown", "id": "76acac17-b423-42af-8dd1-897695e27880", "metadata": {}, "source": [ "### Step 4: Scale the service\n", "\n", "Let us assume that we want to scale the replica of the docker service corresponding to the house rate prediction to 10. It could be achieved using the following command:\n", "\n", "```bash\n", " foo@bar:$ docker service scale house_rate_prediction_service=10\n", "\n", "```\n", "\n", "### Step 5: list the services and inspect them\n", "In this step, you will list all the services of the docker swarm and inspect the `house_rate_prediction_service` service.\n", "\n", "Command to list all the services:\n", "\n", "```bash\n", " foo@bar:$ docker service ls\n", "\n", "```\n", "\n", "Command to inspect the service:\n", "```bash\n", " foo@bar:$ docker service inspect --pretty house_rate_prediction_service\n", "\n", "```\n", "\n", "### Step 6: Information about the service:\n", "To check which node is executing the service `house_rate_prediction_service`, execute the following command in the terminal of manager node:\n", "\n", "```bash\n", " foo@bar:$ docker service ps house_rate_prediction_service\n", "\n", "```\n", "\n", "### Step 7: Delete the service\n", "In the final step, we delete the `house_rate_prediction_service` from the docker swarm.\n", "\n", "Command to delete the service:\n", "```bash\n", " foo@bar:$ docker service rm house_rate_prediction_service\n", "\n", "```\n", "\n", "Finally check whether `house_rate_prediction_service` is deleted or not using following command:\n", "\n", "```bash\n", " foo@bar:$ docker service ps house_rate_prediction_service\n", "\n", "```\n", "The above command would return empty list indicating that there is no node that executes the `house_rate_prediction_service` service. " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }