docker mounting volumes on host

前端 未结 6 691
陌清茗
陌清茗 2020-11-28 18:34

I have successfully been able to share folders between a docker container with volumes using

docker run -v /host/path:/container/path ...

B

6条回答
  •  余生分开走
    2020-11-28 18:40

    VOLUME is used in Dockerfile to expose the volume to be used by other containers. Example, create Dockerfile as:

    FROM ubuntu:14.04

    RUN mkdir /myvol  
    RUN echo "hello world" > /myvol/greeting  
    VOLUME /myvol
    

    build the image:

    $ docker build -t testing_volume .

    Run the container, say container1:

    $ docker run -it bash

    Now run another container with volumes-from option as (say-container2)

    $ docker run -it --volumes-from ubuntu:14.04 bash

    You will get all data from container1 /myvol directory into container2 at same location.

    -v option is given at run time of container which is used to mount container's directory on host. It is simple to use, just provide -v option with argument as :. The whole command may be as $ docker run -v :

提交回复
热议问题