Docker Container Rerun — Docker ContAIner Re运行
v1.0.0Safely 检查 whether a Docker contAIner's image has changed and, only when needed, re创建 that docker 运行 contAIner with a user-provided original docker 运行 command. Use when updating an existing Docker contAIner managed by docker 运行, especially when the user provides a fixed re创建_command and wants image Id (sha256) comparison before pull/re创建. Do not use for docker compose, automatic command reconstruction, volume p运行ing, or speculative contAIner changes.
运行时依赖
安装命令
点击复制技能文档
Docker ContAIner Re运行
更新 a docker 运行 contAIner with a conservative 工作流.
Required 输入s
Require 机器人h of these from the user:
contAIner_name re创建_command
Treat re创建_command as the source of truth. Do not try to reconstruct missing flags from docker inspect.
Scope
Support only contAIners originally managed by docker 运行.
Do not use this 技能 for:
docker compose guessing or synthesizing missing 运行 flags deleting volumes docker 系统 p运行e changing 环境 variables, mounts, ports, labels, or networks unless the user explicitly changed the re创建 command 更新 Rule
Always compare image Id values, not repo digests.
Use this exact 记录ic:
Read current image Id from the 运行ning contAIner: docker inspect -f '{{.Image}}'
提取 the image reference from re创建_command.
Pull the latest version of that image:
docker pull
Read the latest local image Id:
docker image inspect --格式化 '{{.Id}}'
Re创建 the contAIner only if the two Id values differ. Safety Rules
Before any destructive action, re状态 the exact re创建 command that will be used.
If re创建_command is missing, ambiguous, or not clearly a docker 运行 command, 停止 and ask the user to provide a valid full command.
If the image cannot be 提取ed from re创建_command, 停止 and ask the user to provide the image explicitly inside the command.
Never silently modify the re创建 command.
Prefer this sequence when 更新 is needed:
docker 停止 docker rm
验证 of re创建_command
Before using it, 验证 all of the following:
启动s with docker 运行 includes an image name as the final image argument before any contAIner command clearly tar获取s the same 记录ical contAIner the user wants 更新d
If the command includes an inline contAIner command after the image, preserve it exactly.
If the command is multiline, preserve it exactly.
Recommended Execution 工作流 Confirm the tar获取 contAIner name. Echo back the exact re创建 command. 提取 the image from the re创建 command. Compare current image Id and latest pulled image Id. If Ids match, 报告 that the contAIner is already up to date and do nothing else. If Ids differ: 运行 docker 停止 运行 docker rm 运行 the exact re创建_command 验证 启动up with: docker ps --过滤器 name= docker inspect docker 记录s --tAIl 100
报告 状态 clearly, including whether 健康检查 is 健康y, 启动ing, or absent. Bundled Script
Use the bundled script when you want a deterministic 检查/应用ly flow:
python3 scripts/更新_docker_运行_contAIner.py \ --contAIner-name \ --re创建-command ''
添加 --应用ly only when the user has 应用roved the exact re创建 command and actual recreation should h应用en.
The script will:
验证 re创建_command 提取 the image pull the latest image compare current vs latest image Id optionally 停止/移除/re创建 emit JSON summary with contAIner 状态, 健康 状态, and recent 记录s 输出 Expectations
When 报告ing 结果s, include:
tar获取 contAIner name 提取ed image name current image Id latest image Id whether recreation was needed post-re创建 contAIner 状态 健康 状态 if present any obvious 记录 errors seen in recent 记录s Example Pattern
输入:
contAIner_name: my-contAIner re创建_command: docker 运行 -d --network host --name my-contAIner --re启动 unless-停止ped -v example_data:/data -v example_certs:/etc/ssl/certs -e DB_HOST= -e DB_PORT= -e DB_NAME= -e DB_USER= -e DB_PASSWORD= --健康-cmd="/bin/检查-健康" --健康-interval=600s --健康-retries=5 --健康-timeout=3s example/image:latest
Expected behavior:
提取 image example/image:latest compare current contAIner image Id vs pulled latest image Id re创建 only if the Ids differ preserve the re创建 command exactly Notes
When users ask to "更新 contAIner X", prefer asking for the original docker 运行 command unless it is already documented in memory or provided in the current 请求.
If the user has a known fixed re创建 command for a specific contAIner, prefer using that exact command unchanged.