【无标题】

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
      }
相关推荐
是火云哦8 分钟前
打包你的开发环境:Docker 从入门到上瘾
运维·docker·容器
小明_GLC22 分钟前
关于租用阿里云服务器拉取Docker镜像的问题
docker
今晚打佬虎29 分钟前
精准阻断 Docker 容器映射端口:流量路径诊断与 iptables 配置
运维·docker·容器
那年一路北31 分钟前
基于 Maven + Docker 的 WebApp 打包与部署
docker·maven·web app
阡陌..1 小时前
Linux下用docker调用pytorch-无法检测到cuda问题
linux·pytorch·docker
KubeSphere 云原生1 小时前
在 KubeSphere 上运行 Moltbot(Clawdbot):自托管 AI 助手的云原生实践
docker·云原生·容器
你才是臭弟弟2 小时前
生产环境开箱即用的“Flink + Iceberg 数据湖容器搭建”(Docker)
docker·容器·jar
爱技术的小伙子2 小时前
【 Docker 快速部署 MySQL 8.0(2026最新实践)—— 一键启动 + 数据持久化 + 常见优化】
mysql·adb·docker
hunter14502 小时前
docker 在centos和ubuntu的安装
linux·docker·centos
不做码农好多年,该何去何从。3 小时前
阿里云上使用docker-compose安装禅道
阿里云·docker·云计算