Docker 1 12新功能探索 5 创建服务
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.****.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
通过docker service create创建服务,使用docker service ls确认服务信息,docker service ps确认详细运行状况,更是在create的时候提供了众多的Option,这些Option在其他流行的编排工具中稍作比较,大多大同小异,使用方便。
docker service create
Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG…]
Options
short | option usage | explain | default setting |
---|---|---|---|
–constraint value | Placement constraints | (default []) | |
–container-label value | Container labels | (default []) | |
–endpoint-mode string | Endpoint mode (vip or dnsrr) | ||
-e | –env value | Set environment variables | (default []) |
–help | Print usage | ||
-l | –label value | Service labels | (default []) |
–limit-cpu value | Limit CPUs | (default 0.000) | |
–limit-memory value | Limit Memory | (default 0 B) | |
–log-driver string | Logging driver for service | ||
–log-opt value | Logging driver options | (default []) | |
–mode string | Service mode (replicated or global) | (default “replicated”) | |
–mount value | Attach a mount to the service | ||
–name string | Service name | ||
–network value | Network attachments (default []) | ||
-p | –publish value | Publish a port as a node port | (default []) |
–replicas value | Number of tasks | (default none) | |
–reserve-cpu value | Reserve CPUs | (default 0.000) | |
–reserve-memory value | Reserve Memory | (default 0 B) | |
–restart-condition string | Restart when condition is met (none, on-failure, or any) | ||
–restart-delay value | Delay between restart attempts | (default none) | |
–restart-max-attempts value | Maximum number of restarts before giving up | (default none) | |
–restart-window value | Window used to evaluate the restart policy | (default none) | |
–stop-grace-period value | Time to wait before force killing a container | (default none) | |
–update-delay duration | Delay between updates | ||
–update-failure-action string | Action on update failure (pause | continue) | |
–update-parallelism uint | Maximum number of tasks updated simultaneously (0 to update all at once) | (default 1) | |
-u | –user string | Username or UID | |
–with-registry-auth | Send registry authentication details to swarm agents | ||
-w | –workdir string | Working directory inside the container |
事前确认
事前确认:没有运行中的service
[root@host31 ~]# docker service lsID NAME REPLICAS IMAGE COMMAND[root@host31 ~]#
- 1
- 2
- 3
创建Service
创建一个sonarqube的service,创建4个副本,公开port 9000以用于外部访问
[root@host31 ~]# docker service create --name sonar_service --replicas 4 -p 9000:9000/tcp sonarqube48rkq87ktq38q6v0sjr9cu3of[root@host31 ~]#
- 1
- 2
- 3
确认结果
确认生成了4个副本的sonar_service都已经正常启动
[root@host31 ~]# docker service lsID NAME REPLICAS IMAGE COMMAND48rkq87ktq38 sonar_service 4/4 sonarqube[root@host31 ~]#
- 1
- 2
- 3
- 4
确认启动的4个副本以怎样的分布启动在哪个node上
[[email protected] ~]# docker service ps sonar_serviceID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERRORc0vp4yrr751j1nrblkpw9wek5 sonar_service.1 sonarqube host33 Running Running less than a second agoaypn2tn8lj2k1xzttnc3k84at sonar_service.2 sonarqube host34 Running Running less than a second ago04seclvx14qrvfemol21y05px sonar_service.3 sonarqube host34 Running Running less than a second ago9y6x1uvj289f1flx08nl0mkws sonar_service.4 sonarqube host31 Running Running 3 minutes ago[[email protected] ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
sonarqube的web画面确认
给我老师的人工智能教程打call!http://blog.****.net/jiangjunshow
通过docker service create创建服务,使用docker service ls确认服务信息,docker service ps确认详细运行状况,更是在create的时候提供了众多的Option,这些Option在其他流行的编排工具中稍作比较,大多大同小异,使用方便。
docker service create
Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG…]
Options
short | option usage | explain | default setting |
---|---|---|---|
–constraint value | Placement constraints | (default []) | |
–container-label value | Container labels | (default []) | |
–endpoint-mode string | Endpoint mode (vip or dnsrr) | ||
-e | –env value | Set environment variables | (default []) |
–help | Print usage | ||
-l | –label value | Service labels | (default []) |
–limit-cpu value | Limit CPUs | (default 0.000) | |
–limit-memory value | Limit Memory | (default 0 B) | |
–log-driver string | Logging driver for service | ||
–log-opt value | Logging driver options | (default []) | |
–mode string | Service mode (replicated or global) | (default “replicated”) | |
–mount value | Attach a mount to the service | ||
–name string | Service name | ||
–network value | Network attachments (default []) | ||
-p | –publish value | Publish a port as a node port | (default []) |
–replicas value | Number of tasks | (default none) | |
–reserve-cpu value | Reserve CPUs | (default 0.000) | |
–reserve-memory value | Reserve Memory | (default 0 B) | |
–restart-condition string | Restart when condition is met (none, on-failure, or any) | ||
–restart-delay value | Delay between restart attempts | (default none) | |
–restart-max-attempts value | Maximum number of restarts before giving up | (default none) | |
–restart-window value | Window used to evaluate the restart policy | (default none) | |
–stop-grace-period value | Time to wait before force killing a container | (default none) | |
–update-delay duration | Delay between updates | ||
–update-failure-action string | Action on update failure (pause | continue) | |
–update-parallelism uint | Maximum number of tasks updated simultaneously (0 to update all at once) | (default 1) | |
-u | –user string | Username or UID | |
–with-registry-auth | Send registry authentication details to swarm agents | ||
-w | –workdir string | Working directory inside the container |
事前确认
事前确认:没有运行中的service
[root@host31 ~]# docker service lsID NAME REPLICAS IMAGE COMMAND[root@host31 ~]#
- 1
- 2
- 3
创建Service
创建一个sonarqube的service,创建4个副本,公开port 9000以用于外部访问
[root@host31 ~]# docker service create --name sonar_service --replicas 4 -p 9000:9000/tcp sonarqube48rkq87ktq38q6v0sjr9cu3of[root@host31 ~]#
- 1
- 2
- 3
确认结果
确认生成了4个副本的sonar_service都已经正常启动
[root@host31 ~]# docker service lsID NAME REPLICAS IMAGE COMMAND48rkq87ktq38 sonar_service 4/4 sonarqube[root@host31 ~]#
- 1
- 2
- 3
- 4
确认启动的4个副本以怎样的分布启动在哪个node上
[[email protected] ~]# docker service ps sonar_serviceID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERRORc0vp4yrr751j1nrblkpw9wek5 sonar_service.1 sonarqube host33 Running Running less than a second agoaypn2tn8lj2k1xzttnc3k84at sonar_service.2 sonarqube host34 Running Running less than a second ago04seclvx14qrvfemol21y05px sonar_service.3 sonarqube host34 Running Running less than a second ago9y6x1uvj289f1flx08nl0mkws sonar_service.4 sonarqube host31 Running Running 3 minutes ago[[email protected] ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7