I have a dockerized application that uses the filesystem to store lots of state. The application code is contained in the docker image
I am considering a update strategy which involves sharing the volume between two containers, but making sure that at most one container at a time can write to that filesystem.
The workflow would be:
The destination takes as its value the path where the file or directory is mounted in the container. May be specified as destination , dst , or target . The readonly option, if present, causes the bind mount to be mounted into the container as read-only. May be specified as readonly or ro .
Docker images are stored as series of read-only layers. When we start a container, Docker takes the read-only image and adds a read-write layer on top.
From the official Docker docs: We've already seen that Docker images are read-only templates from which Docker containers are launched. Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image.
You can re-mount your volume from inside the container, in the rw
mode, like that:
mount -o remount,rw /mnt/data
The catch is that mount syscall is not allowed inside the Docker containers by default so that you would have to run it in a privileged mode:
docker run --privileged ...
or enable the SYS_ADMIN capability
SYS_ADMIN Perform a range of system administration operations.
docker run --cap-add=SYS_ADMIN --security-opt apparmor:unconfined
(note that I have had to also add --security-opt apparmor:unconfined, to make this work on Ubuntu).
Also, remounting the rw
volume back to ro
might be tricky, as some process(es) might have already opened some files inside it for writing , in which case the remount
will fail with is busy
error message.
But my guess is that you can just restart the container instead (as it would be the one running an old version of the app).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With