How to merge host folder with container folder in

2019-04-20 21:03发布

问题:

I have Wikimedia running on Docker. Wikimedia's extensions reside in extensions/ folder which initially contain built-in extensions (one extensions = one subfolder)

Now I wish to add new extensions. However I don't prefer the option of modifying the Dockerfile or creating new commit on the existing container.

Is it possible to create a folder in the host (e.g. /home/admin/wikimedia/extensions/) which is to be merged (not to overwrite) with the extension folder in the container? So whenever I want to install new extension, I just copy the extension folder to the host /home/admin/wikimedia/extensions/

回答1:

You can mount a volume from your host to a separate location than the extension folder, then in your startup script, you can copy the contents to the container's directory. You will need to rebuild your host once.

For example:

Dockerfile:
  RUN cp startup-script /usr/local/bin/startup-script
  CMD /usr/local/bin/startup-script

startup-script:
   #!/bin/bash
   cp /mnt/extensions /path/to/wikipedia/extensions
   /path/to/old-startup-script $@

docker run -d -v /home/admin/wikimedia/extensions:/mnt/extensions wikipedia

That is one way to get around this problem, the other way would be to maintain a separate data container for extensions, then you will mount this and maintain it outside of the wikipedia container. It would have to have all the extensions in it.

You can start one like so:

 docker run -d -v /home/admin/wikimedia/extensions:/path/to/wikipedia/extensions --name extensions busybox tail -f /dev/null
 docker run -d --volumes-from extensions wikipedia


标签: docker