I’m sorry I wasn’t clear, I meant a working example of the actual behaviour of what you are trying to achieve…
This is what I’ve seen so far:
Step 1. create a volume, with a name that mimics a bit the multi-app nature of resin devices:
$ docker volume create data_123
data_123
Step 2. user this dockerfile that mimics your setup:
FROM resin/intel-nuc-alpine
# Create a file at buildtime
RUN mkdir -p /data && \
touch /data/buildtime_$(date +"%Y%m%d_%H%M%S") && \
ls -la /data
# Create a file at runtime
CMD touch /data/runtime_$(date +"%Y%m%d_%H%M%S") &&\
ls -la /data
and build it:
$ docker build . -t volumetest --no-cache
Sending build context to Docker daemon 4.608kB
Step 1/3 : FROM resin/intel-nuc-alpine
---> 6d809cef67ac
Step 2/3 : RUN mkdir -p /data && touch /data/buildtime_$(date +"%Y%m%d_%H%M%S") && ls -la /data
---> Running in 7e4d457ecacb
total 8
drwxr-xr-x 2 root root 4096 Jul 12 16:35 .
drwxr-xr-x 1 root root 4096 Jul 12 16:35 ..
-rw-r--r-- 1 root root 0 Jul 12 16:35 buildtime_20170712_163549
---> 7f32d82166dc
Removing intermediate container 7e4d457ecacb
Step 3/3 : CMD touch /data/runtime_$(date +"%Y%m%d_%H%M%S") && ls -la /data
---> Running in 5148ab535b56
---> 10e067ecb815
Removing intermediate container 5148ab535b56
Successfully built 10e067ecb815
Successfully tagged volumetest:latest
Step 3 is to run this container, pointing to the volume:
$ docker run -ti --rm -v data_123:/data volumetest
starting version 3.2.2
total 8
drwxr-xr-x 2 root root 4096 Jul 12 16:35 .
drwxr-xr-x 1 root root 4096 Jul 12 16:35 ..
-rw-r--r-- 1 root root 0 Jul 12 16:35 buildtime_20170712_163549
-rw-r--r-- 1 root root 0 Jul 12 16:35 runtime_20170712_163557
Thus the build file has been copied, and the runtime file is created there.
Then running it again:
$ docker run -ti --rm -v data_123:/data volumetest
starting version 3.2.2
total 8
drwxr-xr-x 2 root root 4096 Jul 12 16:35 .
drwxr-xr-x 1 root root 4096 Jul 12 16:35 ..
-rw-r--r-- 1 root root 0 Jul 12 16:35 buildtime_20170712_163549
-rw-r--r-- 1 root root 0 Jul 12 16:35 runtime_20170712_163557
-rw-r--r-- 1 root root 0 Jul 12 16:35 runtime_20170712_163559
Thus the runtime file from last time was kept (the changes are permanent) and the new runtime created file is there too…
Step 4. Then if the image is rebuilt:
$ docker build . -t volumetest --no-cache
Sending build context to Docker daemon 4.608kB
Step 1/3 : FROM resin/intel-nuc-alpine
---> 6d809cef67ac
Step 2/3 : RUN mkdir -p /data && touch /data/buildtime_$(date +"%Y%m%d_%H%M%S") && ls -la /data
---> Running in 975cf5d2617f
total 8
drwxr-xr-x 2 root root 4096 Jul 12 16:39 .
drwxr-xr-x 1 root root 4096 Jul 12 16:39 ..
-rw-r--r-- 1 root root 0 Jul 12 16:39 buildtime_20170712_163905
---> 95c026b69c6f
Removing intermediate container 975cf5d2617f
Step 3/3 : CMD touch /data/runtime_$(date +"%Y%m%d_%H%M%S") && ls -la /data
---> Running in 2817e73cc8e0
---> 5204caa3fab8
Removing intermediate container 2817e73cc8e0
Successfully built 5204caa3fab8
Successfully tagged volumetest:latest
and run again, then the new buildtime file is not actually copied in there but the very first existing file remained, but the runtime file does gets created:
$ docker run -ti --rm -v data_123:/data volumetest
starting version 3.2.2
total 8
drwxr-xr-x 2 root root 4096 Jul 12 16:39 .
drwxr-xr-x 1 root root 4096 Jul 12 16:39 ..
-rw-r--r-- 1 root root 0 Jul 12 16:35 buildtime_20170712_163549
-rw-r--r-- 1 root root 0 Jul 12 16:35 runtime_20170712_163557
-rw-r--r-- 1 root root 0 Jul 12 16:35 runtime_20170712_163559
-rw-r--r-- 1 root root 0 Jul 12 16:39 runtime_20170712_163911
So is this the behaviour that you are looking for?