-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Milestone
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels