上一节我们部署好了 Swarm 集群,下面部署一个运行httpd镜像的service进行演示
root@host03:~# docker service create --name web_server httpd # 创建一个httpd的service,名字是 web_server
9aa10i3l6xjwjacy95jsd061f
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
service创建过程会占用一个终端,下面新开一个 host03 的终端,查看service创建过程中的一些状态
root@host03:~# docker service ls # 初始状态,没有任何service
ID NAME MODE REPLICAS IMAGE PORTS
root@host03:~# docker service ls # service创建中,要求副本数1 ,实际副本数0,如果耗时较长,多数是在下载镜像
ID NAME MODE REPLICAS IMAGE PORTS
9aa10i3l6xjw web_server replicated 0/1 httpd:latest
root@host03:~# docker service ls # service创建成功,副本数达到 1
ID NAME MODE REPLICAS IMAGE PORTS
9aa10i3l6xjw web_server replicated 1/1 httpd:latest
root@host03:~# docker service ps web_server # 查看某service的运行状态,目前该容器运行在host03上
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
jykct1jmfrte web_server.1 httpd:latest host03 Running Running 3 minutes ago
root@host03:~# docker ps # 在host03上验证容器运行情况
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
128adb220d05 httpd:latest "httpd-foreground" 3 minutes ago Up 3 minutes 80/tcp web_server.1.jykct1jmfrtei1pu0jh5unwil
root@host02:~# docker service ls # docker service 命令只能在 swarm manager 上执行,在swarm worker 上执行会报如下错误
Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.