拉完后,我正在尝试检查容器是否正在运行最后可用的图像
像这样
for container in $(docker-compose ps -q)
do
oldImage=$(docker inspect $container -f "{{.Image}}" | sed 's/sha256://')
imageName=$(docker inspect $container -f "{{.Config.Image}}")
newImage=$(docker image inspect $imageName -f "{{.Id}}" | sed 's/sha256://')
if [[ "$newImage" != "$oldImage" ]]; then
echo "new image found $imageName"
echo "new image $newImage"
echo "old image $oldImage"
echo "restaring ... "
fi
done
我可以检查容器的镜像是否与可用的新镜像不同,但是我没有重新启动它的服务名称。
有什么想法吗?
最佳答案
我找到了这个解决方案
#!/bin/bash
set -e
for serviceName in $(docker-compose config --services)
do
container=$(docker-compose ps -q $serviceName)
if [[ "$container" == "" ]]; then
continue
fi
oldImage=$(docker inspect $container -f "{{.Image}}" | sed 's/sha256://')
imageName=$(docker inspect $container -f "{{.Config.Image}}")
newImage=$(docker image inspect $imageName -f "{{.Id}}" | sed 's/sha256://')
if [[ "$newImage" != "$oldImage" ]]; then
echo "new image found $imageName"
echo "new image $newImage"
echo "old image $oldImage"
echo "restaring ... $serviceName"
set -v
docker-compose stop $serviceName
docker-compose up -d $serviceName
set -nv
fi
done
关于docker - docker-compose,如何检查容器是否正在运行最后一个镜像?然后重新启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52284511/