From d1597500a36b63c40615a700b3c397e1d40fa7cf Mon Sep 17 00:00:00 2001 From: khs1994 Date: Sat, 25 Nov 2017 10:26:58 +0800 Subject: [PATCH] Add Swarm mode deploy --- swarm_mode/deploy.md | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 swarm_mode/deploy.md diff --git a/swarm_mode/deploy.md b/swarm_mode/deploy.md new file mode 100644 index 0000000..18b71a9 --- /dev/null +++ b/swarm_mode/deploy.md @@ -0,0 +1,53 @@ +## 部署服务 + +我们使用 `docker service` 命令来管理 `Swarm` 集群中的服务,该命令只能在管理节点运行。 + +### 新建服务 + +现在我们在上一节创建的 `Swarm` 集群中运行一个名为 `nginx` 服务。 + +```bash +$ docker service create --replicas 3 -p 80:80 --name nginx nginx:1.13.7-alpine +``` + +现在我们使用浏览器,输入任意节点 IP ,即可看到 nginx 默认页面。 + +### 查看服务 + +使用 `docker service ls` 来查看当前 `Swarm` 集群运行的服务。 + +```bash +$ docker service ls +ID NAME MODE REPLICAS IMAGE PORTS +kc57xffvhul5 nginx replicated 3/3 nginx:1.13.7-alpine *:80->80/tcp +``` + +使用 `docker service ps` 来查看某个服务的详情。 + +```bash +$ docker service ps nginx +ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS +pjfzd39buzlt nginx.1 nginx:1.13.7-alpine swarm2 Running Running about a minute ago +hy9eeivdxlaa nginx.2 nginx:1.13.7-alpine swarm1 Running Running about a minute ago +36wmpiv7gmfo nginx.3 nginx:1.13.7-alpine swarm3 Running Running about a minute ago +``` + +使用 `docker service logs` 来查看某个服务的日志。 + +```bash +$ docker service logs nginx +nginx.3.36wmpiv7gmfo@swarm3 | 10.255.0.4 - - [25/Nov/2017:02:10:30 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-" +nginx.3.36wmpiv7gmfo@swarm3 | 10.255.0.4 - - [25/Nov/2017:02:10:30 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-" +nginx.3.36wmpiv7gmfo@swarm3 | 2017/11/25 02:10:30 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.255.0.4, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.99.102" +nginx.1.pjfzd39buzlt@swarm2 | 10.255.0.2 - - [25/Nov/2017:02:10:26 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-" +nginx.1.pjfzd39buzlt@swarm2 | 10.255.0.2 - - [25/Nov/2017:02:10:27 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-" +nginx.1.pjfzd39buzlt@swarm2 | 2017/11/25 02:10:27 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.99.101" +``` + +### 删除服务 + +使用 `docker service rm` 来从 `Swarm` 集群移除某个服务。 + +```bash +$ docker service rm nginx +```