Does anyone have a working trivial example of a Dockerfile & command line that mount an external directory from linux into the docker image? -
all i'm looking dockerfile & docker build+run commands on linux view /var/tmp via mount point within container. issues here complicated cases or involve os/x & windows or trying more mount volume. case i've tried mount /var/tmp onto /foobar of busybox image, run container image, , use "ls /foobar" see contents.
running "docker version 1.6.1, build 97cd073" on linux 4.0.1 w/ aufs using local repostory.
http://docs.docker.com/userguide/dockervolumes/
notes that:
mount host directory data volume in addition creating volume using -v flag can mount directory docker daemon's host container. <snip> $ sudo docker run -d -p --name web -v /src/webapp:/opt/webapp training/webapp python app.py mount host directory, /src/webapp, container @ /opt/webapp. note: if path /opt/webapp exists inside container's image, contents replaced contents of /src/webapp on host stay consistent expected behavior of mount useful testing, example can mount our source code inside container , see our application @ work change source code. directory on host must specified absolute path , if directory doesn't exist docker automatically create you.
i'm using local repository acquires "/data" directory via "-v" switch docker run:
docker run -d -p 5000 \ -v '/var/lib/docker/registry:/data/registry/storage' \ 'kampka/registry';
this seems work hosts's /var/lib/docker/registry directory gets entries added it.
so try simple test myself: build minimal copy of busybox access /var/tmp on host system.
from localhost:5000/lembark/busybox maintainer lembark@wrkhors.com volume [ "/foobar" ] env path /bin workdir / entrypoint [ "/bin/sh" ]
at point running "docker build" executes volume command, not create mount point:
$ docker build --tag="localhost:5000/lembark/hak" . ; sending build context docker daemon 7.68 kb sending build context docker daemon step 0 : localhost:5000/lembark/busybox ---> c1a1f5abbf79 step 1 : maintainer lembark@wrkhors.com ---> using cache ---> b46677881767 step 2 : volume /foobar ---> running in 7127bdbcfb56 ---> bcf9c3f1c441 removing intermediate container 7127bdbcfb56 step 3 : env path /bin ---> running in 89f92c815860 ---> 780fea54a67f removing intermediate container 89f92c815860 step 4 : workdir / ---> running in aa3871c408a1 ---> 403190e9415b removing intermediate container aa3871c408a1 step 5 : entrypoint /bin/sh ---> running in 4850561f7ebd ---> 77c32530b4a9 removing intermediate container 4850561f7ebd built 77c32530b4a9
the "volume /foobar" in step 2 seems indicate mount point should available @ runtime.
at point using either of
docker run --rm -t -i localhost:5000/lembark/hak; docker run --rm -t -i -v /foobar localhost:5000/lembark/hak; docker run --rm -t -i -v /var/tmp:/foobar localhost:5000/lembark/hak;
leaves me with:
# ls -al /foobar ls: /foobar: no such file or directory
adding mkdir before volume leaves me /foobar directory anonymous volume, not mapping /var/tmp:
... run [ "mkdir", "/foobar" ] volume [ "/foobar" ]
or
# made local ./foobar directory, added image. copy [ "foobar", "/foobar" ]
bofh of these leave /foobar, no way map external directory it. instead keep getting anonymous volumes:
# mount | grep foobar; /dev/mapper/vg00-var--lib on /var/lib/docker/aufs/mnt/dd12f3e11a6fcb88627412a041b7c910e4d32dc1bf0c15330899036c59d7b3d9/foobar type xfs (rw,noatime,nodiratime,attr2,inode64,logbufs=8,logbsize=256k,logdev=/dev/vg02/var-lib-extlog,noquota)
no combination or without each of mkdir, volume, copy, or -v leaves me viewing /var/tmp undef /foobar.
thanks
this works me
dockerfile
from busybox:latest volume /foo/bar
command
$ docker build -t bb . sending build context docker daemon 2.048 kb sending build context docker daemon step 0 : busybox:latest ---> 8c2e06607696 step 1 : volume /foo/bar ---> running in a94615dd3353 ---> fa500ba91831 built fa500ba91831 $ docker run -it -v /tmp:/foobar bb ls /foobar [contents of /tmp directory]
note don't need volume
command this. docker run -it -v /tmp:/foobar busybox:latest ls /foobar
works well.
Comments
Post a Comment