Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge host folder with container folder in Docker?

Tags:

docker

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/

like image 866
Pahlevi Fikri Auliya Avatar asked Jan 15 '15 09:01

Pahlevi Fikri Auliya


People also ask

How do hosts connect to containers?

Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.

What is host path and container path in Docker?

It is actually the path within the container where you would like to mount /path/from/host . For example, if you had a directory on the host, /home/edward/data , and you wanted the contents of that directory to be available in the container at /data , you would use -v /home/edward/data:/data .


1 Answers

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
like image 62
Michael Avatar answered Oct 17 '22 08:10

Michael