我写了这个简单的Makefile来说明我的问题。
$make target
dep
作为依赖项并提取图像docker image list -q $(IMG)
的检查找不到我的图像。
IMG := hello-world
.PHONY: target
target: dep
ifeq ($(shell docker image list -q $(IMG)),)
echo "docker image list did not recognize the pull"
endif
.PHONY: dep
dep:
@docker pull $(IMG)
后续。在读取任何规则之前,它会被[[替换放入Makefile中。
您可能想在target
规则的命令中执行该测试:target: dep
if test -z "$$(docker image list -q $(IMG))"; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi
我们可以将命令更改为只运行docker image inspect
-如果图像存在,它将返回true状态,否则返回false:
target: dep
if ! docker image inspect "$(IMG))" >/dev/null 2>&1; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi