Docker Service

本文详细介绍了Docker Swarm服务管理的使用方法,包括inspect、logs、ps、create、update和ls等命令,以及如何创建和管理服务,如设置复制模式、挂载卷和发布端口等。通过示例演示了如何创建和调整服务实例数量,帮助读者掌握Docker Swarm集群的运维技巧。
摘要由CSDN通过智能技术生成

依赖docker swarm集群管理

用法:docker service

inspect   //查看具体服务信息

logs        //查看服务日志

ps         //列出正在运行的服务

create //创建服务

update //更新服务

ls         //列出所有服务

docker service create参考

具体可以查看help语法帮助

#docker service create --help

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

Create a new service

Options:

--config config Specify configurations to expose to the service

--constraint list Placement constraints

--container-label list Container labels

--credential-spec credential-spec Credential spec for managed service account (Windows only)

-d, --detach Exit immediately instead of waiting for the service to converge

--dns list Set custom DNS servers

--dns-option list Set DNS options

--dns-search list Set custom DNS search domains

--endpoint-mode string Endpoint mode (vip or dnsrr) (default "vip")

--entrypoint command Overwrite the default ENTRYPOINT of the image

-e, --env list Set environment variables

--env-file list Read in a file of environment variables

--generic-resource list User defined resources

--group list Set one or more supplementary user groups for the container

--health-cmd string Command to run to check health

--health-interval duration Time between running the check (ms|s|m|h)

--health-retries int Consecutive failures needed to report unhealthy

--health-start-period duration Start period for the container to initialize before counting retries towards unstable (ms|s|m|h)

--health-timeout duration Maximum time to allow one check to run (ms|s|m|h)

--host list Set one or more custom host-to-IP mappings (host:ip)

--hostname string Container hostname

--init Use an init inside each service container to forward signals and reap processes

--isolation string Service container isolation mode

-l, --label list Service labels

--limit-cpu decimal Limit CPUs

--limit-memory bytes Limit Memory

--log-driver string Logging driver for service

--log-opt list Logging driver options

--mode string Service mode (replicated or global) (default "replicated")

--mount mount Attach a filesystem mount to the service

--name string Service name

--network network Network attachments

--no-healthcheck Disable any container-specified HEALTHCHECK

--no-resolve-image Do not query the registry to resolve image digest and supported platforms

--placement-pref pref Add a placement preference

-p, --publish port Publish a port as a node port

-q, --quiet Suppress progress output

--read-only Mount the container's root filesystem as read only

--replicas uint Number of tasks

--replicas-max-per-node uint Maximum number of tasks per node (default 0 = unlimited)

--reserve-cpu decimal Reserve CPUs

--reserve-memory bytes Reserve Memory

--restart-condition string Restart when condition is met ("none"|"on-failure"|"any") (default "any")

--restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) (default 5s)

--restart-max-attempts uint Maximum number of restarts before giving up

--restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h)

--rollback-delay duration Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s)

--rollback-failure-action string Action on rollback failure ("pause"|"continue") (default "pause")

--rollback-max-failure-ratio float Failure rate to tolerate during a rollback (default 0)

--rollback-monitor duration Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) (default 5s)

--rollback-order string Rollback order ("start-first"|"stop-first") (default "stop-first")

--rollback-parallelism uint Maximum number of tasks rolled back simultaneously (0 to roll back all at once) (default 1)

--secret secret Specify secrets to expose to the service

--stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) (default 10s)

--stop-signal string Signal to stop the container

--sysctl list Sysctl options

-t, --tty Allocate a pseudo-TTY

--update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s)

--update-failure-action string Action on update failure ("pause"|"continue"|"rollback") (default "pause")

--update-max-failure-ratio float Failure rate to tolerate during an update (default 0)

--update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 5s)

--update-order string Update order ("start-first"|"stop-first") (default "stop-first")

--update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1)

-u, --user string Username or UID (format: [:])

--with-registry-auth Send registry authentication details to swarm agents

-w, --workdir string Working directory inside the container

create常用参数解析

--mode 指定服务的运行模式,只有两种:

replicated 复制模式

global 全局模式

--mount 指定服务创建的容器的volume卷映射信息

src 源目录,宿主机上的目录

dst 目标路径,容器内的路径

--publish 简写-p,设置服务的网络映射关系。

用法: -p mode=host,published=81,target=80

mode 网络模式,只有ingress和host两种,ingress是入口模式,端口将暴露在swarm集群,host是主机模式,仅在容器所在的主机上绑定容器的端口

published 发布的端口,宿主机暴露的端口

target 容器的端口

--quiet 简写-q,省略输出service update与create的信息,如果不省略,会输出过程信息,这个内容比较多,而且由于linux的刷新机制,其实过程输出包含了大量的重复内容,通过-q参数可以限制过程输出的打印,只输出最终的结果

--replicas 指定分片的数量,当>1时,其中一个挂掉了,会自动分配到其他的swarm节点

参考例子

#创建nginx服务

docker service create nginx nginx:latest

#创建服务并挂载目录

docker service create --mount src=<VOLUME-NAME>,dst=<CONTAINER-PATH> --name myservice <IMAGE>

#创建服务并挂载端口

docker service create --name nginx --replicas 2 -p mode=host,published=80,target=80 hub.test.com:5000/almi/nginx:0.1

#--network=swarm_test

#replicas 2 创建2个容器,hub.test.com为私有仓库

#修改服务实例数量为2(replicas)

docker service scale nginx=3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值