We need to orchestrate the Docker, and especially when using it in production environments. The Docker community released some tools which can be used for this purpose. Let us discuss some of these tools.
This tool is used for the purpose of hosting and scheduling a cluster of Docker containers. You will learn about how to create a Docker Swarm on your machine and VirtualBox.
Each of the nodes used in the Docker Swarm should be in a position to access the Docker Hub for downloading and running images in your container. To create a Docker Swarm on your machine, follow the steps given below:
1. List all the machines available in your system. Use the following command:
2. Create a VirtualBox machine and give it the name “local.” Use the command given below:
3. The machine which has been created should then be loaded into the shell. Use the following command:
4. You should then use the Docker Swarm image so as to generate a discovery token. The following command can be used for this purpose:
If the latest image of “swarm: latest” is not found in your local system, it will be pulled to your system. The command will run verbosely, and you will observe the following output:
5. The token should then be saved in a safe place.
This is the one responsible for orchestrating and scheduling containers in the entire system. The process of hosting the containers is done by the Swarm agents. They are a kind of regular Docker daemon which you can communicate with via the Docker remote API. Let us try to create two Swarm managers:
1. Under your VirtualBox, create a Swarm manager. This is shown below:
2. Open the VirtualBox Manager, which should have the “local” machine and the “swarm-master” machine which we have just created. These are shown below:
3. Create the swarm node:
4. Create another agent, and give it the name “swarm-agent-1”. This is shown below:
The two agents should now be available in your VirtualBox.
What we need to do is to establish a connection to the swarm, show the information related to it, and then start the image related to the swarm. Follow the steps given below:
1. Begin by running the following command:
The Docker environment will be pointed to the machine which is running the swarm master.
2. Use the “docker” command so as to get information about your new swarm
Note that at this moment, the master is running both the swarm agent container and the swarm manager. However, this is not a good technique in a production environment since the agent can develop problems