生成的两个选项
docker run ...
现有容器:
-
assaflavie/runlike
-我这么做是因为另一个标签有问题(但这个不支持批量检查)
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike <container>
-
nexdrew/rekcod
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod <container>
最后的剧本看起来像(
未经测试
)以下内容:
# get names of running containers (names persist recreation)
running_containers=$(docker ps --format "{{.Names}}")
# stop running containers
docker stop $running_containers
# generate recreate script
containers=$(docker ps --all --format "{{.Names}}")
echo '#!/bin/sh' > ./recreate.sh
while read -r cname; do
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike "$cname" >> ./recreate.sh
done <<< "$containers"
chmod +x ./recreate.sh
# ... do some action now (maybe also manually check recreate script) ...
# recreate containers
docker rm --force $containers
./recreate.sh
# restart containers that were previously running
docker start $running_containers
这似乎解决了我的需求,但是一些人注意到,这些工具可能会错过Docker特性,甚至可能包含bug(例如,我已经注意到RekCod中的错误),所以请谨慎使用。