bash - Cannot write into ~/.m2 in docker maven container -


why aren't files written in /root/.m2 in maven3 docker image persistent during build?

a simple dockerfile:

from maven:3-jdk-8 run touch /root/.m2/testfilehere && ls -a /root/.m2 run  ls -a /root/.m2 cmd ["bash"] 

produces following output.

$ docker build -t test --no-cache . sending build context docker daemon 2.048 kb step 1 : maven:3-jdk-8  ---> 42e3884987fb step 2 : run touch /root/.m2/testfilehere && ls -a /root/.m2  ---> running in 1c1dc5e9f082 . .. testfilehere  ---> 3da352119c4d removing intermediate container 1c1dc5e9f082 step 3 : run ls -a /root/.m2  ---> running in df506db8c1dd . ..  ---> d07cc155b20e removing intermediate container df506db8c1dd step 4 : run stat  /root/.m2/testfilehere  ---> running in af44f30aafe5 stat: cannot stat ‘/root/.m2/testfilehere’: no such file or directory command '/bin/sh -c stat  /root/.m2/testfilehere' returned non-zero code: 1 

the file created @ first command gone when intermmediate container exists.

also, not happen in ubuntu image, maven.

edit: using add hostfile /root/.m2/containerfile work workaround, not want.

that's because /root/.m2 defined volume in image. when container runs volume, volume storage is not part of unionfs - data not stored in container's writable layer:

a data volume specially-designated directory within 1 or more containers bypasses union file system.

the first run command creates file in volume, that's in intermediary container own volume. file isn't saved image layer because it's in volume.

the second run command running in new intermediary container has own volume. there's no content in volume base image, volume empty in new container.

if want pre-populate volume data, need in dockerfile you've seen.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -