简体   繁体   English

在 docker-compose 中挂载主机 Vm

[英]Mounting the host Vm in docker-compose

I want to mount the host vm in Docker for Windows in my container (for backup purpose).我想在我的容器中的 Docker for Windows 中安装主机 vm(用于备份目的)。 I found a short article about it which says to run我找到了一篇关于它的简短文章,上面写着要运行

docker container run --rm -it -v /:/host alpine

to do this.去做这个。 I tried and it works fine.我试过了,效果很好。 Now i wanted to put it into a docker-compose file.现在我想把它放到一个 docker-compose 文件中。 However然而

volumes:
  - / :/host:ro

doesn't work.不起作用。 I don't get an error message, the folder is just empty.我没有收到错误消息,文件夹是空的。 The space in front of the colon was necessary, without it I got an error.冒号前面的空格是必要的,没有它我会出错。

Does someone know how to set this up in docker-compose?有人知道如何在 docker-compose 中进行设置吗?

Just write the same way you did on docker run , do not put any space between directories.只需按照您在docker run上所做的相同方式编写,不要在目录之间放置任何空格。

volumes:
   - /:/host:ro

But with :ro docker will not write anything to it and will simply read the contents of the directory.但是使用:ro docker 不会向它写入任何内容,只会读取目录的内容。 If you want to write, remove the :ro .如果要写入,请删除:ro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM