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

248
Visualizações
How to mount current directory as read-only but still allow changes inside the container?

I have a situation where:

  • I want to mount a directory ~/tmp/mycode to /mycode readonly
  • I want to be able to edit the files in the directory, so I can't just run -v /my/local/path/tmp/mycode:/mycode
    • I want it to not persist changes on the host filesystem though so I can't mount it read/write
  • ~/tmp/mycode is rather large

Basically I want to be able to edit the files in the mounted volume but not have those changes persisted.

My current workflow is to create a dummy container using a dockerfile:

ADD . /mycode

and then execute that container.

However as the repository grows, this step takes longer and longer to perform, because the only way I can think is to make a complete copy of ~/tmp/mycode in order to be able to manipulate the files in the container.

I've also thought about mounting the directory and copying it inside the container and committing that container, but that has the same issue.

Is there a way to run a docker container to allow file edits without persisting them on the host short of copying the whole directory?

I am using the latest docker for mac, currently Version 17.03.1-ce-mac5 (16048).

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is fairly trivial to do 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 mount the code from your directory read only and create the overlay inside the container so that /mnt/rocode is read only, but /mycode is writable.

Make sure that your kernel is 3.18+ and that you have overlay in your /proc/filesystems.

about 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