简体   繁体   English

如何在 docker 容器和主机之间共享数据

[英]how to share data between docker container and host

I'm working on a read the docs documentation where I use docker.我正在阅读使用 docker 的文档文档。 To customize it, I d like to share the css folder between the container and host, in order to avoid building always a new image to see the changes.为了自定义它,我想在容器和主机之间共享css文件夹,以避免总是构建一个新图像来查看更改。 The goal is, that I can just refresh the browser and see the changes.目标是,我可以刷新浏览器并查看更改。

I tried something like this, but it doesn't work:我尝试过这样的事情,但它不起作用:

docker run -v ~/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest

What is wrong in this command?这个命令有什么问题?

The path of the folder I'd like to share is:我要分享的文件夹路径是:

Documents/my-documentation/docs/source/_static/css

Thanks for your help!谢谢你的帮助!

I'm guessing that the ~ does not resolve correctly.我猜 ~ 不能正确解析。 The tilde character ("~") refers to the home directory of your user;波浪号(“~”)是指用户的主目录; usually something like /home/your_username .通常类似于/home/your_username

In your case, it sounds like your document isn't in this directory anyway.就您而言,听起来您的文档无论如何都不在此目录中。

Try:尝试:

docker run -v Documents/my-documentation/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest

I have no mac to test with, but I suspect the command should be as below ( Documents is a subfolder to inside your home directory denoted by ~ )我没有要测试的 mac,但我怀疑命令应该如下所示( Documents是您的主目录内的子文件夹,由~表示)

docker run -v ~/Documents/my-documentation/docs/source/_static/css:/docs/source/_static/css -p 80:80 -it my-docu:latest

In your OP you mount the host folder ~/docs/source/_static/css , which does not make sense if your files are in Documents/my-documentation/docs/source/_static/css as that would correspond to ~/Documents/my-documentation/docs/source/_static/css在您的 OP 中,您挂载主机文件夹~/docs/source/_static/css ,如果您的文件位于Documents/my-documentation/docs/source/_static/css中,这将没有意义,因为它对应于~/Documents/my-documentation/docs/source/_static/css

Keep in mind that Docker is still running inside a VM on Mac, so you will need to give a host path that is valid on that VM请记住 Docker 仍在 Mac 上的 VM 内运行,因此您需要提供在该 VM 上有效的主机路径

What you can do to get a better view of the situation is to start an interactive container where you mount the root file system of the host vm root into /mnt/vm-root .为了更好地了解情况,您可以做的是启动一个交互式容器,将主机 vm root 的根文件系统挂载到/mnt/vm-root中。 That way you can see what paths are available to mount and how they should be formatted when you pass them using the -v flag to the docker run command这样,当您使用-v标志将它们传递给 docker 运行命令时,您可以查看哪些路径可用于挂载以及应如何格式化它们

docker run --rm -it -w /mnt/vm-root -v /:/mnt/vm-root ubuntu:latest bash

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

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