Docker 更新已经创建容器的相关配置 作者: Chuwen 时间: 2022-10-18 分类: Docker 有时候创建容器时忘记加上 `--restart=always`,导致当服务器重启、Docker 重启,容器未能自启动,导致服务不可用。这时候可以通过 `docker update`命令来更新容器的配置。 查看 `docker update` 支持哪些操作 ```shell ➜ ~ docker update --help Usage: docker update [OPTIONS] CONTAINER [CONTAINER...] Update configuration of one or more containers Options: --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit the CPU real-time period in microseconds --cpu-rt-runtime int Limit the CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) --kernel-memory bytes Kernel memory limit -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --pids-limit int Tune container pids limit (set -1 for unlimited) --restart string Restart policy to apply when a container exits ``` ## 修改容器的重启策略 语法如下,*container_name*、*container_id* 仅需要传入任意一个即可: ```shell docker update --restart=always ``` *container_name*、*container_id* 可以使用 `docker ps` 查看获取 ```shell CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f358a08b3b5 snowdreamtech/frpc "/bin/sh -c '/usr/bi…" 4 weeks ago Up 25 hours frpc_nowtime-test ``` ### 示例 ```shell docker update --restart=always b631b689edb0 ``` ### 更多的使用方法请参考 docker update 命令的官方文档 https://docs.docker.com/engine/reference/commandline/update/ 标签: Docker