在主机上挂载开发Docker容器目录 [英] Mounting development docker container directory on host

查看:78
本文介绍了在主机上挂载开发Docker容器目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker进行软件开发,因为我可以将所有依赖项(编译器,库等)捆绑在一个良好的包含环境中,而不会污染主机.

我通常做事的方式(我想这很普遍):我在主机上有一个目录,仅包含源代码,该目录使用docker卷安装到开发容器中,在其中构建我的软件并被执行.由于卷是同步的,因此源中的任何更改都将反映在容器中.

这是一个陷阱:使用代码编辑器时,由于无法从主机访问软件依赖关系,因此软件依赖关系被视为已损坏.因此,棉绒等不起作用.

我希望能够将容器中的/usr/local/include 挂载到主机上,以便正确配置我的编辑器,可以修复所有警告./p>

我想docker volume在这里不是解决方案,因为它将覆盖包含的文件系统...

此外,我正在使用Windows(此处没有选择),因此我的流程是:

Windows>桑巴舞Linux主机>码头工人>容器

并且我宁愿不切换IDE(VS代码).

有什么想法吗?谢谢!

解决方案

您基本上希望可以将卷从容器反向装载到主机.不幸的是,这在Docker中是不可能的,并且此问题有多种变体: 解决方案

You basically wish you could reverse mount a volume from the container to the host. This is unfortunately not possible with Docker, and there are variants of this question here: How to mount a directory in docker container to host

You're stuck with copying the files from the container to the host. As far as the host path matching /usr/local/include or having to use a different folder depends upon your setup.

The easiest solution which would not require changing the docker image would be to use docker cp to copy the files.

Otherwise, you could automate this by having the image on entry (after installing all dependencies) copy the files to /tmp/include and mount a host volume to that location.

这篇关于在主机上挂载开发Docker容器目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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