如何在容器上使用本地文件? [英] How can I use a local file on container?

查看:81
本文介绍了如何在容器上使用本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个容器来运行程序.我正在使用预配置映像,现在我需要运行该程序.但是,这是一个机器学习程序,我需要计算机上的数据集才能运行.

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.

有什么办法可以通过某些docker命令来进行此引用吗?还是使用Dockerfile?

Is there any way to do this reference with some docker command? Or using Dockerfile?

推荐答案

是的,您可以执行此操作.您所描述的是绑定安装.请参阅 https://docs.docker.com/storage/bind-mounts/有关该主题的文档.

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.

例如,如果要将主目录中的文件夹装入容器中的/mnt/mydata中,可以执行以下操作:

For example, if I want to mount a folder from my home directory into /mnt/mydata in a container, I can do:

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

现在,容器内的/mnt/mydata将可以访问我的主机上的/Users/andy/mydata.

Now, /mnt/mydata inside the container will have access to /Users/andy/mydata on my host.

请记住,如果您使用的是Mac的Docker或Windows的Docker,默认情况下主机上会允许使用特定目录:

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或Windows上使用Docker Machine,则Docker Engine守护程序仅具有对macOS或Windows文件系统的有限访问权限. Docker Machine尝试自动共享您的/Users(macOS)或C:\ Users(Windows)目录.因此,您可以使用来在macOS上挂载文件或目录.

If you are using Docker Machine on Mac or Windows, your Docker Engine daemon has only limited access to your macOS or Windows filesystem. Docker Machine tries to auto-share your /Users (macOS) or C:\Users (Windows) directory. So, you can mount files or directories on macOS using.

2019年7月更新:

我已经更新了文档链接和命名,以确保正确无误.这些类型的安装架称为绑定安装架".有关适用于Mac或Windows的Docker的片段不再出现在文档中,但仍应适用.我不确定为什么要删除它(我的Mac版Docker仍然在主机上具有允许的安装路径的明确列表).

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. I'm not sure why they removed it (my Docker for Mac still has an explicit list of allowed mounting paths on the host).

这篇关于如何在容器上使用本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆