Home > Article > Operation and Maintenance > How to configure a highly available container orchestration platform (such as Docker Swarm) on Linux
How to configure a highly available container orchestration platform (such as Docker Swarm) on Linux
Introduction:
With the rapid development of cloud computing and container technology, more and more enterprises choose to use containers to build and manage applications. Docker is one of the most popular container technologies currently, and Docker Swarm, as the container orchestration tool officially provided by Docker, can help us quickly build and manage clusters of multiple containers. This article will introduce how to configure a highly available container orchestration platform on Linux and how to use Docker Swarm to orchestrate and manage containers.
Configuration environment:
First, we need to install Docker on the Linux server. Taking Ubuntu as an example, you can execute the following command to install:
$ sudo apt-get update $ sudo apt-get install docker.io
Configure Docker Swarm:
Initialize Docker Swarm
First, we need to initialize a host Manage nodes for Swarm. Execute the following command on the host:
$ sudo docker swarm init
After successful execution, a command will be returned, similar to:
Swarm initialized: current node (xxxx) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token xxxxxxxx
Save this command for use when configuring other nodes.
Add Swarm Node
Next, we can add other nodes to the Swarm cluster. Execute the saved command on the new node, similar to:
$ sudo docker swarm join --token xxxxxxxx
After successful execution, the new node will successfully join the Swarm cluster.
View Swarm nodes
You can use the following command to view the nodes in Swarm:
$ sudo docker node ls
The execution result is similar to:
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION xxxxx node1 Ready Active Reachable 19.03.13 xxxxx node2 Ready Active Leader 19.03.13
By status and Availability, we can know the information of each node in the Swarm cluster.
Organizing containers:
We have successfully configured the Docker Swarm cluster, and then we can use Swarm to orchestrate and manage containers. The following is a simple example for creating and running an Nginx service.
Create a network
In the Swarm cluster, there is an overlay network for communication between containers. We can create an overlay network, for example:
$ sudo docker network create -d overlay my_network
Create a service
Use the following command to create an Nginx service:
$ sudo docker service create --name my_nginx --network my_network --publish 8080:80 nginx
This command will be in the Swarm cluster Create a service named my_nginx, use the my_network network, and map the container's port 80 to the host's port 8080.
View service status
You can use the following command to view the status of the service:
$ sudo docker service ls
The execution result is similar to:
ID NAME MODE REPLICAS IMAGE PORTS xxxxx my_nginx replicated 1/1 nginx:latest *:8080->80/tcp
Through the REPLICAS column, We can know the number of container instances currently running.
Expansion Service
If you need to increase the number of container instances, you can use the following command to expand:
$ sudo docker service scale my_nginx=3
This command will expand the number of instances of the my_nginx service to 3 .
Summary:
This article introduces how to configure a highly available container orchestration platform (such as Docker Swarm) on Linux, and demonstrates how to use Docker Swarm through a simple example Orchestration and management of containers. Of course, in addition to the above examples, Docker Swarm has more functions and usages, and readers can conduct in-depth study and research according to their own needs. I hope this article can help readers and provide some reference for building a highly available container orchestration platform in a Linux environment.
The above is the detailed content of How to configure a highly available container orchestration platform (such as Docker Swarm) on Linux. For more information, please follow other related articles on the PHP Chinese website!