【无标题】

Docker开机自动重启及自动启动容器

Windows开机自动重启

勾选 Start Docker Desktop when you sign in to your computer

设置容器自动启动

1.docker update 命令

bash 复制代码
	Usage:  docker update [OPTIONS] CONTAINER [CONTAINER...]
	
	Update configuration of one or more containers
	
	Aliases:
	  docker container update, docker update
	
	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)
	  -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
  1. restart命令详解

    Use the --restart flag to specify a container's restart policy. A restart policy controls whether the Docker daemon restarts a container after exit. Docker supports the following restart policies:

    Policy Result
    no Do not automatically restart the container when it exits. This is the default.
    on-failure[:max-retries] Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.
    unless-stopped Restart the container unless it's explicitly stopped or Docker itself is stopped or restarted.
    always Always restart the container regardless of the exit status. When you specify always, the Docker daemon tries to restart the container indefinitely. The container always starts on daemon startup, regardless of the current state of the container.
  2. 使用命令进行更新设置

    bash 复制代码
    docker update --restart=always <CONTAINER>
  3. 查看是否设置成功,检查RestartPolicy内容

    bash 复制代码
    docker inspect <CONTAINER>
    bash 复制代码
      "RestartPolicy": {
          "Name": "always",
          "MaximumRetryCount": 0
      }
相关推荐
不知疲倦的仄仄21 分钟前
2025最新版Docker讲解/面试/命令/容器化技术
运维·docker·容器
哈里谢顿4 小时前
修改并重新部署docker项目流程
docker
code喵喵5 小时前
docker-compose安装常用中间件
docker·中间件·容器
山岚的运维笔记6 小时前
AlpineLinux使用docker部署prometheus
docker·容器·prometheus
咚咚?7 小时前
docker 启动中间件
docker·中间件·容器
csdn_aspnet8 小时前
在 Docker 上安装和配置 Kafka、选择用于部署 Kafka 的操作系统
docker·kafka
乌托邦的逃亡者13 小时前
Docker的/var/lib/docker/目录占用100%的处理方法
运维·docker·容器
OKUNP17 小时前
Docker高级管理--容器通信技术与数据持久化
docker·容器·php
用户68554496927320 小时前
第一周作业
docker
星辰云-1 天前
【超详细】CentOS系统Docker安装与配置一键脚本(附镜像加速配置)
linux·docker·centos