1. What is Docker Swarm? Docker Swarm is a cluster management tool officially provided by Docker. Its main function is to abstract several Docker hosts into a whole and manage various Docker resources on these Docker hosts through a unified entrance. Swarm is similar to Kubernetes, but is lighter and has fewer features than Kubernetes. Docker Swarm, like Docker Compose, is Docker's official container orchestration project. The difference is that Docker Compose is a tool for creating multiple containers on a single server or host, while Docker Swarm can create container cluster services on multiple servers or hosts. For the deployment of microservices, Docker Swarm is obviously more suitable. Since Docker 1.12.0, Docker Swarm has been included in the Docker engine (docker swarm), and a service discovery tool has been built in. We no longer need to configure Etcd or Consul for service discovery as before. 2. Docker Swarm Architecture This diagram as a whole is actually in a so-called cluster, which may correspond to one or more actual servers. Docker is installed on each server and the HTTP-based Docker API is enabled. This cluster has a SwarmManager manager, which is used to manage container resources in the cluster. The manager's management object is not at the server level but at the cluster level. That is to say, through the Manager, we can only issue general instructions to the cluster but cannot specify what to do on a specific server (this is also the essence of Swarm). As for the specific management implementation method, the Manager exposes an HTTP interface to the outside world, and external users manage the cluster through this HTTP interface. For slightly larger clusters, it is best to set aside an actual server as a dedicated manager. For learning purposes, you can also put the manager and the managed on the same server. 3. Rolling Update of Docker Swarm Service Docker Swarm can achieve smooth service upgrades, that is, services are updated without downtime and clients are unaware. Let us demonstrate this through a specific example. Here we will deploy an nginx-based web application service on the node node. We will create two versions of the same application: version 1 and version 2 Create a Dockerfile and compile it using docker build. FROM nginx RUN echo '<h1>Swarm:Version 1 <h1>' > /usr/share/nginx/html/index.html Note: In order to make the image accessible to every node in the Swarm cluster, we upload the generated image to our own image repository. docker login docker build -t collenzhao/mynginx:v1 . docker push collenzhao/mynginx:v1 Create a Swarm service, that is, start the container through the image docker service create -p 7788:80 --replicas 3 --name myswarmtest collenzhao/mynginx:v1 View the deployed services through docker service ls. View the detailed information of the deployed service through docker service ps myswarmtest The effect is shown in the figure below Update the previous Dockerfile, note that the version number becomes: 2 FROM nginx RUN echo '<h1>Swarm:Version 2 <h1>' > /usr/share/nginx/html/index.html Compile using docker build docker build -t collenzhao/mynginx:v2 . Upload to Docker Hub using Docker push docker push collenzhao/mynginx:v2 Update the service deployed in Swarm before, the version number becomes 2 docker service update --image collenzhao/mynginx:v2 myswarmtest The effect is as follows This concludes this article on sample code for implementing rolling updates of services with Docker Swarm. For more information about Docker Swarm rolling updates, please search for previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Methods and steps to upgrade MySql5.x to MySql8.x
>>: js+css to realize three-level navigation menu
Table of contents Step 1: Build the framework Ste...
XML is designed to describe, store, transmit and ...
The new official website is online, but the exper...
This article example shares the specific code of ...
The first time I used the essay, I felt quite awkw...
Table of contents 1. Images 1. What is a mirror? ...
This tutorial is only applicable to Windows syste...
nginx (engine x) is a high-performance HTTP and r...
Table of contents 1. Cancel duplicate requests 2....
Mysql installation, configuration, and optimizati...
Hash Join Hash Join does not require any indexes ...
REPLACE Syntax REPLACE(String,from_str,to_str) Th...
This article example shares the specific code for...
This article mainly introduces the sample code of...
Table of contents introduction Distinguish betwee...