docker service update命令
kevin.Zhu 发布于:2022-9-16 19:22 分类:文摘 有 21 人浏览,获得评论 0 条
https://www.yiibai.com/docker/service_update.html
docker service update
命令用于更新服务。它根据指定的参数更新服务。 必须以管理员节点为目标运行此命令。参数与docker service create
相同。请查看有关进一步信息的描述。
用法
docker service update [OPTIONS] SERVICE
选项
名称,简写 | 默认 | 说明 |
---|---|---|
--constraint
|
Placement constraints | |
--container-label
|
Container labels | |
--dns
|
Set custom DNS servers | |
--dns-option
|
Set DNS options | |
--dns-search
|
Set custom DNS search domains | |
--endpoint-mode
|
Endpoint mode (vip or dnsrr) | |
--env , -e
|
Set environment variables | |
--env-file
|
Read in a file of environment variables | |
--group
|
Set one or more supplementary user groups for the container | |
--health-cmd
|
Command to run to check health | |
--health-interval
|
Time between running the check (ns/us/ms/s/m/h) | |
--health-retries
|
0 | Consecutive failures needed to report unhealthy |
--health-timeout
|
Maximum time to allow one check to run (ns/us/ms/s/m/h) | |
--host
|
Set one or more custom host-to-IP mappings (host:ip) | |
--hostname
|
Container hostname | |
--label , -l
|
Service labels | |
--limit-cpu
|
0.000 | Limit CPUs |
--limit-memory
|
0 B | Limit Memory |
--log-driver
|
Logging driver for service | |
--log-opt
|
Logging driver options | |
--mode
|
replicated | Service mode (replicated or global) |
--mount
|
Attach a filesystem mount to the service | |
--name
|
Service name | |
--network
|
Network attachments | |
--no-healthcheck
|
false | Disable any container-specified HEALTHCHECK |
--publish , -p
|
Publish a port as a node port | |
--replicas
|
Number of tasks | |
--reserve-cpu
|
0.000 | Reserve CPUs |
--reserve-memory
|
0 B | Reserve Memory |
--restart-condition
|
Restart when condition is met (none, on-failure, or any) | |
--restart-delay
|
Delay between restart attempts (ns/us/ms/s/m/h) | |
--restart-max-attempts
|
Maximum number of restarts before giving up | |
--restart-window
|
Window used to evaluate the restart policy (ns/us/ms/s/m/h) | |
--secret
|
Specify secrets to expose to the service | |
--stop-grace-period
|
Time to wait before force killing a container (ns/us/ms/s/m/h) | |
--tty , -t
|
false | Allocate a pseudo-TTY |
--update-delay
|
0s | Delay between updates (ns/us/ms/s/m/h) (default 0s) |
--update-failure-action
|
pause | Action on update failure (pause/continue) |
--update-max-failure-ratio
|
0 | Failure rate to tolerate during an update |
--update-monitor
|
0s | Duration after each task update to monitor for failure (ns/us/ms/s/m/h) (default 0s) |
--update-parallelism
|
1 | Maximum number of tasks updated simultaneously (0 to update all at once) |
--user , -u
|
Username or UID (format: |
|
--with-registry-auth
|
false | Send registry authentication details to swarm agents |
--workdir , -w
|
Working directory inside the container |
相关命令
命令 | 描述 |
---|---|
docker service create | |
docker service inspect | |
docker service logs | 获取服务的日志 |
docker service ls | 列出服务 |
docker service rm | 删除一个或多个服务 |
docker service scale | 缩放一个或多个复制服务 |
docker service update | 更新服务 |
实例
更新服务
$ docker service update --limit-cpu 2 redis
执行没有参数更改的滚动重启
$ docker service update --force --update-parallelism 1 --update-delay 30s redis
添加或删除安装
使用--mount-add
或--mount-rm
选项可以添加或删除服务的bind-mount
或卷。
以下示例创建一个将测试数据卷安装到/somewhere
的服务。 下一步更新服务以将其他卷卷安装到/somehere-elsevolume
。最后一步卸载/somewhere
安装点,有效地删除测试数据卷。 每个命令返回服务名称。
$ docker service create \
--name=myservice \
--mount \
type=volume,source=test-data,target=/somewhere \
nginx:alpine \
myservice
myservice
$ docker service update \
--mount-add \
type=volume,source=other-volume,target=/somewhere-else \
myservice
myservice
$ docker service update --mount-rm /somewhere myservice
myservice
回滚到以前版本的服务
使用--rollback
选项回滚到以前版本的服务。这将将服务恢复到最新的docker service update
命令之前的配置。
以下示例将服务的副本数从4
更新为5
,然后回滚到上一个配置。
$ docker service update --replicas=5 web
web
$ docker service ls
ID NAME MODE REPLICAS IMAGE
80bvrzp6vxf3 web replicated 0/5 nginx:alpine
回滚Web服务…
$ docker service update --rollback web
web
$ docker service ls
ID NAME MODE REPLICAS IMAGE
80bvrzp6vxf3 web replicated 0/4 nginx:alpine
其他选项也可以与--rollback
组合使用,例如--update-delay 0
执行回滚,而不会在任务之间延迟:
$ docker service update \
--rollback \
--update-delay 0s
web
web
添加或删除秘密
使用--secret-add
或--secret-rm
选项添加或删除服务的秘密。
以下示例添加了一个名为ssh-2
的秘密,并删除ssh-1
:
$ docker service update \
--secret-add source=ssh-2,target=ssh-2 \
--secret-rm ssh-1 \
myservice