在容器和主机之间共享文件 [英] Sharing files between container and host

查看:112
本文介绍了在容器和主机之间共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个带有/ var / my_folder卷的Docker容器。那里的数据是持久的:当我关闭容器时,它仍然在那里。
但也想在主机上提供数据,因为我想使用未安装在容器中的IDE进行代码处理。

I'm running a docker container with a volume /var/my_folder. The data there is persistent: When I close the container it is still there. But also want to have the data available on my host, because I want to work on code with an IDE, which is not installed in my container.

那么我如何在主机上有一个/ var / my_folder文件夹,该文件夹也可以在我的容器中找到?

So how can I have a folder /var/my_folder on my host machine which is also available in my container?

我正在使用Linux Mint。

I'm working on Linux Mint.

感谢您的帮助。

谢谢。 :)

推荐答案

链接:管理容器中的数据

您的基本运行命令想要的就是...

The basic run command you want is ...

docker run -dt --name containerName -v /path/on/host:/path/in/container

问题是,安装卷(出于您的目的)将覆盖其中的卷容器

The problem is that mounting the volume will, (for your purposes), overwrite the volume in the container

克服此问题的最佳方法是在安装后创建要共享的文件(在容器内部)。

the best way to overcome this is to create the files (inside the container) that you want to share AFTER mounting.

ENTRYPOINT命令在docker run上执行。因此,如果文件是作为入口点脚本的一部分生成的,而不是作为构建的一部分生成的,那么一旦挂载它们就可以从主机上使用。

The ENTRYPOINT command is executed on docker run. Therefore, if your files are generated as part of your entrypoint script AND not as part of your build THEN they will be available from the host machine once mounted.

解决方案是因此,要运行在ENTRYPOINT脚本中创建文件的命令。

The solution is therefore, to run the commands that creates the files in the ENTRYPOINT script.

如果失败,在构建过程中将文件复制到另一个目录,然后将其复制回ENTRYPOINT脚本。

Failing this, during the build copy the files to another directory and then COPY them back in your ENTRYPOINT script.

这篇关于在容器和主机之间共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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