Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!