Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the high availability of docker

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure the high availability of docker". In the daily operation, I believe many people have doubts about how to configure the high availability of docker. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to configure the high availability of docker". Next, please follow the editor to study!

Docker compose

Docker compose divides the managed containers into three layers, engineering (project), service (service) and container (contaienr). All the files (docker-compose.yml, extends files or environment variable files, etc.) under the directory where docker compose runs constitute a project, which is the current directory name if no special project name is specified. A project can contain multiple services, and each service defines the images, parameters, and dependencies of the container. A service can include multiple container instances. Docker compose does not solve the problem of load balancing, so you need to use other tools to achieve service discovery and load balancing.

Install docker compose

Get docker-compose-linux-x86_64 and place it in the / bin directory, make soft links and add executable permissions

Chmod + x docker-compose-linux-x86_64ln-s docker-compose-linux-x86_64 docker-compose

Import haproxy and nginx to facilitate subsequent load balancing testing

Docker load-i haproxydocker load-I nginx

Write the compose configuration file in / tmp/

[root@foundation50 compose] # vim docker-compose.yml

Create a file to install the httpd service and start httpd in the web1 httpd service

[root@foundation50 compose] # vim web1/dockerfilefrom rhel7:v1 expose 80 run yum install-y httpd add index.html / var/www/html cmd ["/ usr/sbin/httpd", "- d", "foreground"]

Create a haproxy.cfg configuration file in haproxy

View

View statistics for haproxy

Visit 172.25.50.1

Health examination

Close web3

Docker swarm

Prepare three virtual machines

Server1,server2,server3 install docker and start the service

You need to run docker swarm init on one node, and then run the join command on the other node

[root@server1] # docker swarm init [root@server2~] # docker swarm join\ >-- tokenswmtkn-1-51igcdpg4cbgaokq535qis01osel396of153sdlp8k0ljn0rou-2m9sltwkc4uq1vfmp79ous0e4\ > 172.25.50.2Viru 2377 this node joined a swarm as a worker.

View node status on server1

Nginx has been imported earlier, and then flsak has been imported into three machines

[root@server1 ~] # docker load-I flask.tar [root@server2 ~] # docker load-I flask.tar [root@server3 ~] # docker load-I flask.tar

To distinguish between different backend load balancers, a statement showing the hostname written by python is used to import flask and os

Open the flask image and put the demo.py script under root

Submit

[root@server1 python] # docker commit vm1 python:demo

Create a cluster named flask and start three back-end service nodes to read the demo.py script under python

test

[root@foundation50 docker] # for i in {1.. 10}: do curl-w "\ n" http://172.25.50.1;done

Because there are three servers, the polling is completed every three times, and the load balance is realized.

Docker swarm visual web monitoring interface

Import the image and create

[root@server1] # docker load-I visualizer.tar [root@server1] # docker service create-- name=viz-- publish=8080:8080/tcp-- constrain=node.role==manager-- mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock dockersamples/visualizer

View the monitoring page

At this point, the study on "how to configure the high availability of docker" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report