这里写图片描述

通过docker service create创建服务,使用docker service ls确认服务信息,docker service ps确认详细运行状况,更是在create的时候提供了众多的Option,这些Option在其他流行的编排工具中稍作比较,大多大同小异,使用方便。

docker service create

Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG…]

Options

shortoption usageexplaindefault setting
–constraint valuePlacement constraints(default [])
–container-label valueContainer labels(default [])
–endpoint-mode stringEndpoint mode (vip or dnsrr)
-e–env valueSet environment variables(default [])
–helpPrint usage
-l–label valueService labels(default [])
–limit-cpu valueLimit CPUs(default 0.000)
–limit-memory valueLimit Memory(default 0 B)
–log-driver stringLogging driver for service
–log-opt valueLogging driver options(default [])
–mode stringService mode (replicated or global)(default “replicated”)
–mount valueAttach a mount to the service
–name stringService name
–network valueNetwork attachments (default [])
-p–publish valuePublish a port as a node port(default [])
–replicas valueNumber of tasks(default none)
–reserve-cpu valueReserve CPUs(default 0.000)
–reserve-memory valueReserve Memory(default 0 B)
–restart-condition stringRestart when condition is met (none, on-failure, or any)
–restart-delay valueDelay between restart attempts(default none)
–restart-max-attempts valueMaximum number of restarts before giving up(default none)
–restart-window valueWindow used to evaluate the restart policy(default none)
–stop-grace-period valueTime to wait before force killing a container(default none)
–update-delay durationDelay between updates
–update-failure-action stringAction on update failure (pausecontinue)
–update-parallelism uintMaximum number of tasks updated simultaneously (0 to update all at once)(default 1)
-u–user stringUsername or UID
–with-registry-authSend registry authentication details to swarm agents
-w–workdir stringWorking directory inside the container

事前确认

事前确认:没有运行中的service

[root@host31 ~]# docker service ls
ID  NAME  REPLICAS  IMAGE  COMMAND
[root@host31 ~]#

创建Service

创建一个sonarqube的service,创建4个副本,公开port 9000以用于外部访问

[root@host31 ~]# docker service create --name sonar_service --replicas 4 -p 9000:9000/tcp sonarqube
48rkq87ktq38q6v0sjr9cu3of
[root@host31 ~]#

确认结果

确认生成了4个副本的sonar_service都已经正常启动

[root@host31 ~]# docker service ls
ID            NAME           REPLICAS  IMAGE      COMMAND
48rkq87ktq38  sonar_service  4/4       sonarqube
[root@host31 ~]#

确认启动的4个副本以怎样的分布启动在哪个node上

[root@host31 ~]# docker service ps sonar_service
ID                         NAME             IMAGE      NODE    DESIRED STATE  CURRENT STATE                   ERROR
c0vp4yrr751j1nrblkpw9wek5  sonar_service.1  sonarqube  host33  Running        Running less than a second ago
aypn2tn8lj2k1xzttnc3k84at  sonar_service.2  sonarqube  host34  Running        Running less than a second ago
04seclvx14qrvfemol21y05px  sonar_service.3  sonarqube  host34  Running        Running less than a second ago
9y6x1uvj289f1flx08nl0mkws  sonar_service.4  sonarqube  host31  Running        Running 3 minutes ago
[root@host31 ~]#

sonarqube的web画面确认

这里写图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐