Reputation: 56951
I wrote this simple Makefile to illustrate my problem.
$make target
dep
as a dependency and pulls the imagedocker image list -q $(IMG)
does not find my image.What is happening here and how should I fix this?
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)
Upvotes: 0
Views: 52
Reputation: 30961
That test isn't subsequent. It's substituted into the Makefile when it's read, before any rules are executed.
You probably want to perform that test in the commands of the target
rule:
target: dep
if test -z "$$(docker image list -q $(IMG))"; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi
We could change the command to just run docker image inspect
- that will return a true status if the image exists, and false otherwise:
target: dep
if ! docker image inspect "$(IMG))" >/dev/null 2>&1; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi
Upvotes: 1