Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Is it possible to change the read-only/read-write status of a docker mount at runtime?

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:

  • start container A with /data mounted rw
  • start container B with /data mounted ro, and a newer version of the application
  • stop serving requests to container A
  • for container A, make the /data mount read-only
  • for container B, make the /data mount read-write
  • start serving requests to container B
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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).

over 4 years ago · Santiago Trujillo Relatório

0

Not exactly what the OP requested, but I've had a similar question where i needed to get data OUT of the running container, but had mounted RW.

Other ways to extract the data would have taken too long.

My approach ? Stash the container as an image and start a new container from that Image with a mount as RW :D

Initial container start:

docker run  -p 80:8080 --mount type=bind,source="C:\data-folder-local\",target=/data-folder-container-ro,readonly -d imageName:imageTag

Making an image from the container. You can stop this container before/after if you want.

docker commit -a "mud" -m "Damn, mount should be rw, stashing a snapshot to reuse." CONTAINER_ID_HERE snapshotImageName:snapshotImageTag

where CONTAINER_ID_HERE i got from the output of docker ps (https://docs.docker.com/engine/reference/commandline/ps/)

Start a new container from the image made, but this time mount with write rights!

docker run  -p 80:8080 --mount type=bind,source="C:\data-folder-local\",target=/data-folder-container-rw -d snapshotImageName:snapshotImageTag

write out files to the mount folder (on local system) from within your container :D

Hope that helps somebody.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda