从 docker 容器访问文件 [英] Accessing the files out of docker container

查看:80
本文介绍了从 docker 容器访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个 docker 容器镜像,并在容器内工作(设置文件系统、创建代码文件、安装依赖项等).

I have created a docker container image, and working inside the container (setting up filesystem, creating code files, installing dependencies etc).

在我的 Ubuntu 机器上,我在一个名为 /dataset/my_data/ 的目录下保存了一个大文件.

On my Ubuntu machine, I keep a huge file under a directory so called /dataset/my_data/.

当我在容器中工作时,访问上述目录并不简单.是否有可能以交互方式从容器映像内部访问它?如果是,如何?

When I work in the container, it is not straightforward to access the above directory. Is there any possibility to access it from inside the container image interactively? If yes, how?

推荐答案

可以将目录挂载为卷:

docker ... --mount type=bind,source=/dataset/my_data,target=/some/directory

例如,运行一个名为 my-container 的容器并绑定一个卷:

For example, to run a container called my-container with a bound volume:

docker run -it --mount \
  type=bind,source=/dataset/my_data,target=/target/directory \
  my-container

有关所有可用的可能性,请参阅 Docker 文档.

For all available possibilities, see Docker documentation.

这篇关于从 docker 容器访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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