How to use docker swarm to realize Cluster
How to use docker swarm to achieve clusters, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
(1) go compiles web programs.
Mainly to monitor ip:9090/Source browsing, and record the server host and access times.
Code
Package mainimport ("fmt", "log", "net/http", "runtime", "strconv"os") var i int = 0func sayHello (w http.ResponseWriter, r * http.Request) {/ / func sayHello () {ionization + fmt.Print (I) fmt.Print ("\ n") fmt.Print ("visit!" + "\ n") hostname Er: = os.Hostname () if er = = nil {dates: = "jenkins:" + "Login\ n" + "visit Count:" + strconv.Itoa (I) + "\ nHostname:" + hostname w.Write ([] byte (dates)) defer r.Body.Close ()} else {return}} func main () { Fmt.Print ("/ log.txt"] # can be monitored by tail-f log.txt in the container
Docker build-t ip:5000/swarm:0.0. /
Ubuntu@local:~/SWARM$ docker build-t 192.168.175.139:5000/swarm:0.0. / Sending build context to Docker daemon 6.629MB # Sending build context can be used to stop Step 1 26b542a8286bStep 7: FROM ubuntu:16.04-- > a51debf7e1ebStep 2 a51debf7e1ebStep 7: MAINTAINER ZHB-> Using cache-- > 26b542a8286bStep 3 26b542a8286bStep 7: COPY. / arch /-> Using cache-- > aff0b358480cStep 4 Using cache 7: RUN chmod 777 / arch-- > Using cache- -- > 6e07a223b571Step 5 ENTRYPOINT 7: RUN touch / log.txt-- > Using cache-- > 03be86c93b8aStep 6 Accord 7: EXPOSE 9090-> Using cache-- > fe9c6a7ab542Step 7 Accord 7: ENTRYPOINT ["sh" "- c", ". / arch > > / log.txt"]-- > Using cache-- > 6287178e0005Successfully built 6287178e0005Successfully tagged 192.168.175.139:5000/swarm:0.0
Push Mirror
Docker push ip:5000/swarm:0.0
(4) Master node swarm init
Docker swarm init
Other servers join the cluster
Docker swarm join-token * ip:2377
(5) create service
Docker service create-- replicas 6-- name=swarm-service-- publish 9090 IP:5000/swarm:0.0
Overall progress: 0 out of 6 tasks1/6: preparing [= >] 2 tasks1/6 6: preparing [= >] 3 preparing 6: preparing [= >] 4 preparing 6: preparing [= = >] 6: preparing [= >]
(6) web accesses ip:9090/Source and implements load balancing
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.