I'm currently working on a project using Docker Compose and I've hit a snag. I have a service that needs to use some files, but I want these files to be non-persistent. My goal is to ensure that every time the container starts, it copies the files from a specific folder on the host into the container without creating any link between them. This means that any changes made inside the container shouldn't affect the files on the host. Is there a way to manage this? Thanks for any help!
1 Answer
You can achieve this by not mounting any volumes for the specific service. Instead, copy the necessary files directly in your Dockerfile to a designated folder inside the container. Just make sure you skip mounting volumes in your Docker Compose file for that container.
I thought about that, but here’s the catch: I have two identical services running. In one service, changes to a file must be persistent (that’s used by admins), while in the other, it shouldn’t be. For instance, admins modify `example.txt` in Service A, which has its data mounted to the host, but when Service B starts, it should get a fresh copy of `example.txt` but keep any changes isolated within that container. I’d prefer a solution that doesn’t involve rebuilding the image via a Dockerfile.