How can I set the current directory as read-only, but still allow changes inside the container?
I have a situation where:
- I want to set the ~ / tmp / mycode directory to / mycode readonly
- I want to be able to edit files in a directory, so I can't just run
-v /my/local/path/tmp/mycode:/mycode
- I want it to not persist changes to the host filesystem, so I cannot mount it read / write.
- ~ / tmp / mycode is pretty big
Basically I want to be able to edit files on a mounted volume, but not save those changes.
My current workflow is to create a dummy container using a docker file:
ADD . /mycode
and then execute this container.
However, as the repository grows, this step takes longer and longer because the only way I can think of is to make a complete copy of ~ / tmp / mycode so that I can manipulate the files in the container.
I also thought about setting a directory and copying it to a container and transferring that container, but it has the same problem.
Is there a way to start a docker container to allow editing of files without saving them to the host, without copying the entire directory?
I'm using the latest docker for mac, currently Version 17.03.1-ce-mac5 (16048).
source to share
It's pretty trivial to do it with docker and overlay:
docker run --name myenv --privileged -v /my/local/path/tmp/mycode:/mnt/rocode:ro -it ubuntu /bin/bash
docker exec -d myenv /sbin/mount -t overlay overlay -o lowerdir=/mnt/rocode,upperdir=/mycode,workdir=/mnt/code-workdir /mycode
This should install the code from your read-only directory and create an overlay inside the container so that / mnt / rocode is read-only, but / mycode is writable.
Make sure your kernel is 3.18+ and that you have an overlay in your / proc / filesystems.
source to share