I am building a Docker image using a command line like the following:
docker build -t myimage .
Once this command has succeeded, then rerunning it is a no-op as the image specified by the Dockerfile
has not changed. Is there a way to detect if the Dockerfile
(or one of the build context files) subsequently changes without rerunning this command?
答案 0 :(得分:6)
从一个版本到另一个版本查看docker inspect image_name
,如果泊坞窗图像没有改变,则几个信息不会改变。其中一个是docker Id
。因此,我使用Id
信息检查泊坞窗是否已更改,如下所示。首先,可以按如下方式获取图像Id
:
docker inspect --format {{.Id}} docker_image_name
要验证构建后是否有更改,您可以按照以下步骤操作:
代码:这是一个实现上述想法的工作bash脚本:
docker inspect --format {{.Id}} docker_image_name > deploy/last_image_build_id.log
# I get the docker last image id from a file
last_docker_id=$(cat deploy/last_image_build_id.log)
docker build -t docker_image_name .
docker_id_after_build=$(docker inspect --format {{.Id}} docker_image_name
if [ "$docker_id_after_build" != "$last_docker_id" ]; then
echo "image changed"
else
echo "image didn't change"
fi
答案 1 :(得分:2)
如果您正在寻找的话,那么dry-run
选项就不存在。{p}您可以使用其他代码来避免影响现有图片并在输出中查找---> Using cache
(如果您不想要,则删除代码)。