Installing a directory from the parent system to the container in docker

How to set a directory from the parent system to a container in docker?

+53
docker dotcloud
Mar 28 '13 at 22:17
source share
5 answers

* Update - see answer below. this is no longer the correct answer *

You cannot mount them by design because Docker can no longer guarantee a repeatable runtime.

However, you can:

1) Import the root file system of the host and create a new image from it:

tar -C / -c . | docker import - entend/custombase 

2) Import the root bootstrap file system, for example, the result of running 'debootstrap'. (Note that the official โ€œbaseโ€ image was created this way, so you might be better off just launching the โ€œdocker traction baseโ€)

 debootstrap precise ./bootstrap tar -C ./bootstrap -c . | docker import - entend/ubuntubase 

3) Paste the contents of the local directory into the container when it starts.

 IMAGE=base; SRC=./stuff; DST=/tmp/stuff; CMD="echo hello world"; tar -C $src -c . | docker run $IMAGE -i /bin/sh -c "tar -C $DST -x; $CMD" 

This will start the container from $ IMAGE, copy the host directory $ SRC to the container directory $ DST, then run the command $ CMD

This last example is usually used to insert source code before running the build command inside the container.

Hope this helps!

+11
Mar 28 '13 at 22:42
source share

As a recent update, this feature is now released in Docker (although the API has changed since the download request associated with @imiric).

Just use a command like

 docker run -v /tmp:/root myImage 

to mount /tmp from the host as /root inside the image.

Source: https://docs.docker.com/engine/userguide/dockervolumes/

+157
Sep 27 '13 at 19:47
source share

To update this question, it will be possible soon in Docker.

This transfer request actually implemented this function and will soon be merged with the wizard.

You can use it right now if you install this plug .

+5
Jun 24 '13 at 20:34
source share

This IS is possible in docker:

Mounting data in an application container

 docker run -t -i -rm -volumes-from DATA -name client1 ubuntu bash 
+4
Mar 26 '14 at 22:04
source share

THIRD FOR OSX AND WINDOWS

2 consecutive mounts: I think many messages here can use two boot2dockers, the reason you don't see anything is that you are not installing the directory from boot2docker from your host. You basically need 2 consecutive mounts: the first to mount the directory from your host to your system, and the second to mount the new directory from boot2docker to your container as follows:

  • mount the local system on boot2docker

     sudo mount -t vboxsf hostfolder /boot2dockerfolder 
  • mount boot2docker file in linux container

     docker run -v /boot2dockerfolder:/root/containerfolder -i -t imagename 

then when you are inside the container, you will see the contents of your host folder

+4
Dec 6 '14 at 9:14
source share



All Articles