Home  >  Q&A  >  body text

dockerfile - docker VOLUME了一个目录,我在容器里添加文件,主机目录怎么没有出现?

我是用dockerfile build的镜像:
VOLUME /home/user/web
我开启容器,进到bash,进到这个目录,然后新建了一个文件,
然后我回主机目录去查看,但是没有啊?不是说这样挂着的,在容器里面修改了,主机目录会马上出现吗?

高洛峰高洛峰2756 days ago952

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-26 09:04:19

    Using VOLUME in the Dockerfile only declares a volume, which is a mount point. When mounting locally, you need to specify the local directory through -v when running to mount it on the volume you have declared. Of course, for Docker will automatically create undeclared volumes.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-26 09:04:19

    Directory to be mounted when running:

    docker run -v hostpath:/home/user/web xximg

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-26 09:04:19

    You need to use -v to hang in the directory. You can also consider docker-compose.

    reply
    0
  • Cancelreply