TieDad
TieDad

Reputation: 9889

Make always build even when there is no file change

I'm writing a simple Makefile:

all: image 

image: ./common ./source
    docker build -t some-resource -f source/Dockerfile .

.PHONY: all image

I expect that image is only built when files under folders common or source have changes. But when I run make, it always run docker run even without any file change. What's the problem?

Upvotes: 0

Views: 1023

Answers (1)

rveerd
rveerd

Reputation: 4006

When you run make, it will try to make the first target, which is all. This causes make to make the target image. Because there is no actual file named image (you even told make that it is a phony target), it will always execute the docker command.

In this case, it is not possible for make to determine that "common and source have changes". Normally make does this by comparing the modification timestamps of the target and the dependencies but there is no actual target to check (image is not a file).

Upvotes: 2

Related Questions