Docker Community Forums

Share and learn in the Docker community.

Volumes only read write inside the container


(Dignajar) #1

I want to attach a directory from the host /home/guest/app on a Docker container, but this container make changes on this volumes, and I don’t want this changes reflected on the host.

$ docker run -d --name webserver01 -v /home/guest/app:/app
$ docker exec -ti webserver01 'touch /app/test.txt'

In this case the file test.txt is created in the container and in the host. How can I prevent this ?, the file only create inside the container ?


(John Harris) #2

Don’t believe that is possible with volumes. If you need the content to begin with but don’t need changes persisted then maybe you can tar the folder and move it to your build context before creating the image (so you can ADD or COPY it in via the Dockerfile)? Or you can do a docker cp after the container has been created.

(Dignajar) #3

Thanks for your answer.

I’m trying to copy the files with the Dockerfile, but Dockerfile don;t allow me if the files are out of the root of the Dockerfile.

For example, I have my Dockerfile in /home/guest/docker/Dockerfile, and my files are in /home/guest/app

(John Harris) #4

Yes, you need to make sure the files you need are in the context of the build. So either you make the context /home/guest/ and make sure you add anything you don’t want to be added to your .dockerignore file. Or you can just zip up that directory and put it inside your current build context before doing the build (then you would be able to COPY it).

Are you storing the Dockerfile for this app outside of the app directory? Might be a good idea to keep everything for the app in one directory, or at least keep the Dockerfile in a subdirectory of the app directory? Would probably make your building experience easier.

(Dignajar) #5

The problem here is, this app (/home/guest/app) is in Github, and is web-app, the core of a CMS.

I have a lot of this web-sites with the same web-app, my idea is, uses the same files for the core and make the changes necesarry inside the container to each web-site.

And if I made some changes on the web-app, some bug fixes, improvements, etc, this changes are reflected on each Docker container.

I need to think more this solution, I hope do you understand, my english is not so good.

Thanks again!

(John Harris) #6

Wouldn’t you want each website’s changes to be recorded somewhere though? Rather than just existing inside the transient container? Can you post a representation of your filesystem organisation and what needs to go where?

Sounds like your setup may benefit from some refactoring.