Docker ready data with read and write permission

I want to set a docker host data volume. But the container must have read / write permission, and any changes to the data volumes must not affect the data on the host.

I can imagine a solution that mounts multiple volumes of data into one folder, one read, only read and write. But only my second -v works on my command,

docker run -ti --name build_cent1 -v /codebase/:/code:ro -v /temp:/code:rw centos6:1.0 bash

      

+3


source to share


3 answers


Got one answer from nixun on github .

you can just use overlayfs to fix it: mount -t overlay overlay -olowerdir = / codebase, upperdir = / temp, workdir = / workdir / codebase_new docker run -ti --name build_cent1 -v / codebase_new: / code: rw centos6 : 1.0 bash



This solution has good flexibility. Shared folder imaging would have been a solution, but it could not easily update the folder data.

0


source


only this second ' -v

' works in my team,

This may be because both options -v

are trying to set host folders to the same container target folder /code

.

   -v /codebase/:/code:ro 
                 ^^^^^
   -v /temp:/code:rw
            ^^^^^   

      



You can set these host folders to two separate folders in /code

.
How in:

-v /codebase/:/code/base:ro -v /temp:/code/temp:rw.

      

+1


source


Usually, in this case, I think you are the ADD

folder for the Docker image, so any container that runs it will have it in their (writable) filesystem, but the entries will take it to another level.

You need to write Dockerfile

in the folder above the one you want to use, which should look something like this:

FROM my/image
ADD codebase /codebase

      

Then you create a container with docker build -t some-name <path>

. These steps can be added to your application's build scripts (you might find a plugin there). Then you can docker run some-name

.

The downside is there is one copy and image creation, but if you run many containers, they will use the same read-only copy of the layer and write their own changes to the independent layers above.

+1


source







All Articles