问题标签 [overlayfs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
15 浏览

docker - Mount test data volume in docker app and roll back changes

In our dev and demo environments, I'd like to be able to mount a volume (containing a lot of data), change some data through the (dev/demo) application and quickly, easily, and safely revert all changes when we're done.

I'm wondering what would be the best strategy for implementing this and whether Docker has any mechanisms that might help. Ideas so far:

  1. Use BTRFS or similar and mount snapshots of the read-only data.
    Pro: very solid, will definitely do the job
    Con: need to mess with OS-level tools, be root to purge changes, easy to get wrong and lose the base data.

  2. Mount the data in $READ_ONLY_DIR, mount an overlay over the data in $WRITABLE_DIR and create a volume based on $WRITABLE_DIR. The application will write its changes to $WRITABLE_DIR and when we're done with testing or a demo, we can simply purge the changes and start fresh.
    This could in principle be done inside the container (thus having automatic cleanup), but the container would have to be privileged.
    Pro: more lightweight than the snapshot solution.
    Con: we'd still have to manage the cleanup outside of the regular deployment process.

  3. Include the test/demo data in the image instead of a volume. This basically lets Docker handle the overlay logic.
    Pro: solid, will do the job, changes will automatically be ephemeral, no need to set up anything before spinning up another test/demo app.
    Con: huge images. Test/demo data will be gigabytes of data, so this really isn't an option.

Docker already does a lot of overlay magic, so I'd really love to let it handle this one for me, but so far I can't see a way to use its powers for my particular application.

Questions:

  • Are there any best practices for keeping modifications of data in Docker volumes ephemeral?
  • If not: Are there any mechanisms in Docker that I could use to do this?
  • If not: Is there anything else to consider when trying to implement 1. or 2.?

edit: I've tested the overlay solution. This seems to work, but it's not ideal.