Docker Community Forums

Share and learn in the Docker community.

Set File's Last Modified Date to image creation date?

(Coopdis) #1

I’m trying to create a dockerized build system for a project that I’m working on.

The idea is that the SDK and all the dependancies are in a docker image that can be used easily on any system without the standard development environment setup hassles.

The issue I’m facing is that all of the files in the docker container (ie all the SDK files) are given a Last-Modified date equal to the instantiation date of the docker (aka “now”) rather than the time of image creation, which is really when they were last modified.

The result is that make wants to rebuild the whole SDK on every build… which is not going to fly with my users.

If I could set these Last-Modified dates to the time of image creation (or some other earlier date?), then make would work properly… only rebuilding things that have been updated since they were last built.

I tried recursively resetting all of the Last-Modified dates in the SDK at runtime, and that works! But again, it takes a long enough time that it no one is going to want to use this tool.


Thank you

(Jjfraney) #2

I’m not recreating the situation. The file I put in the image has the timestamp of the file. I’m on linux.

My dockerfile:
FROM alpine
COPY time-file /

Note the timestamp of the time-file.
$ touch time-file
$ ls -l
total 4
-rw-r–r-- 1 jfraney jfraney 31 Sep 21 18:36 Dockerfile
-rw-r–r-- 1 jfraney jfraney 0 Sep 21 18:36 time-file

I build with:
$ docker build -t tmptime .

And run, note the timestamp on time-file matches the original time, not the time of the run:
$ date && docker run --rm tmptime stat -c %y time-file
Fri Sep 21 18:48:49 UTC 2018
2018-09-21 18:36:17.000000000

And the image’s create time:
$ docker image inspect --format “{{.Created}}” tmptime

(Coopdis) #3

Yup, you are totally right. My mistake. I was having a different issue.

Sorry for the silly question.

Thank you.