Skip to content

FIXME: Ignore mtime (use only hash of content + permissions) while invalidating cache for ADD command #9391

@askoretskiy

Description

@askoretskiy

Normally Docker uses caching for ADD command.

But this cache gets invalidated once modification date of the file changed.

It should not be the case -- only permissions and content hash (e.g. MD5 or SHA) should be used for this. It is very difficult to preserve mtime in build systems.

Live example:

cat > Dockerfile <<EOF 
FROM debian:jessie
ADD myfile /tmp/
RUN echo 'Done'.
EOF
echo "Some content" > myfile
docker build .
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon 
Step 0 : FROM debian:jessie
 ---> aaabd2b41e22
Step 1 : ADD myfile /tmp/
 ---> f9a488e10e68
Removing intermediate container 3e9f4ee1bc73
Step 2 : RUN echo 'Done'.
 ---> Running in b848d6d8628d
Done.
 ---> d8ba43fbbb65
Removing intermediate container b848d6d8628d
Successfully built d8ba43fbbb65

Check caching is there:

docker build .
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon 
Step 0 : FROM debian:jessie
 ---> aaabd2b41e22
Step 1 : ADD myfile /tmp/
 ---> Using cache
 ---> f9a488e10e68
Step 2 : RUN echo 'Done'.
 ---> Using cache
 ---> d8ba43fbbb65
Successfully built d8ba43fbbb65

Change mtime and build again:

touch myfile
docker build .
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon 
Step 0 : FROM debian:jessie
 ---> aaabd2b41e22
Step 1 : ADD myfile /tmp/
 ---> 8dffbae0fcab
Removing intermediate container 3697ac2594a1
Step 2 : RUN echo 'Done'.
 ---> Running in 0c32cec76e34
Done.
 ---> 5e97b52f28d7
Removing intermediate container 0c32cec76e34
Successfully built 5e97b52f28d7

As you see -- cache is invalidated when mtime changed BUT content stayed the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions