简体   繁体   English

如何在容器上使用本地文件?

[英]How can I use a local file on container?

I'm trying create a container to run a program.我正在尝试创建一个容器来运行程序。 I'm using a pre configurate image and now I need run the program.我正在使用预先配置的映像,现在我需要运行该程序。 However, it's a machine learning program and I need a dataset from my computer to run.但是,它是一个机器学习程序,我需要从我的计算机中获取一个数据集才能运行。

The file is too large to be copied to the container.文件太大,无法复制到容器中。 It would be best if the program running in the container searched the dataset in a local directory of my computer, but I don't know how I can do this.如果容器中运行的程序在我计算机的本地目录中搜索数据集,那将是最好的,但我不知道如何做到这一点。

Is there any way to do this reference with some docker command?有没有办法用一些 docker 命令来做这个参考? Or using Dockerfile?还是使用 Dockerfile?

Yes, you can do this.是的,你可以这样做。 What you are describing is a bind mount.您所描述的是绑定安装。 See https://docs.docker.com/storage/bind-mounts/ for documentation on the subject.有关该主题的文档,请参阅https://docs.docker.com/storage/bind-mounts/

For example, if I want to mount a folder from my home directory into /mnt/mydata in a container, I can do:例如,如果我想将一个文件夹从我的主目录挂载到容器中的/mnt/mydata中,我可以这样做:

docker run -v /Users/andy/mydata:/mnt/mydata myimage

Now, /mnt/mydata inside the container will have access to /Users/andy/mydata on my host.现在,容器内的/mnt/mydata将可以访问我主机上的/Users/andy/mydata

Keep in mind, if you are using Docker for Mac or Docker for Windows there are specific directories on the host that are allowed by default:请记住,如果您使用的是 Mac 版 Docker 或 Windows 版 Docker,则主机上有默认允许的特定目录:

If you are using Docker Machine on Mac or Windows, your Docker Engine daemon has only limited access to your macOS or Windows filesystem.如果您在 Mac 或 Windows 上使用 Docker Machine,则您的 Docker Engine 守护进程只能有限地访问您的 macOS 或 Windows 文件系统。 Docker Machine tries to auto-share your /Users (macOS) or C:\\Users (Windows) directory. Docker Machine 会尝试自动共享您的 /Users (macOS) 或 C:\\Users (Windows) 目录。 So, you can mount files or directories on macOS using.因此,您可以使用 macOS 在 macOS 上挂载文件或目录。

Update July 2019: 2019 年 7 月更新:

I've updated the documentation link and naming to be correct.我已将文档链接和命名更新为正确的。 These type of mounts are called "bind mounts".这些类型的挂载称为“绑定挂载”。 The snippet about Docker for Mac or Windows no longer appears in the documentation but it should still apply.关于 Docker for Mac 或 Windows 的片段不再出现在文档中,但它仍然适用。 I'm not sure why they removed it (my Docker for Mac still has an explicit list of allowed mounting paths on the host).我不确定他们为什么删除它(我的 Docker for Mac 仍然有一个明确的主机上允许安装路径的列表)。

暂无
暂无

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

相关问题 我如何在群集集群中使用本地容器 - How I use a local container in a swarm cluster 如何制作本地docker容器? - How can I make a local docker container? 如何将 weblogic 容器的管理服务器日志保存在本地文件系统中 - How can I save Admin server logs of weblogic container in my local file system 如何在 application.properties 文件中指定环境变量,以便我的应用程序可以在 Z38008DCCA73AZ 中使用 Docker 容器 MySQL 不是本地 MySQL? - How to specify environment variables in application.properties file so my application can use Docker container MySQL not local MySQL in Spring? 如何从 KSQL docker 容器连接到本地 Kafka? - How can I connect to Kafka local from KSQL docker container? 如何将本地目录挂载到现有的 docker 容器? - How can I mount a local directory to an existing docker container? 如何将 docker 容器的 STDOUT 捕获到该容器外部的文件中? - How can I capture STDOUT of a docker container to a file OUTSIDE of that container? 如何使用本地 elrond docker 容器节点进行本地智能合约开发 - How do I use local elrond docker container node for local smart-contract development 如何使用 env 文件将环境变量传递到独立的 vscode 远程容器中? - How can I use an env file to pass environment variables into a standalone vscode remote container? 当我使用 Docker 容器没有使用我的本地 html 文件时,我遇到了问题 - i have problem when i use Docker container is not using my local html file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM