加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何将docker镜像指向我的.m2目录,以便在mac上的docker

发布时间:2020-12-13 19:51:12 所属栏目:Linux 来源:网络整理
导读:当您查看 Dockerfile for a maven build时,它包含以下行: VOLUME /root/.m2 现在,如果这是我的.m2存储库在我的Mac上的地方,这将是很好的 – 但它不是 – 它在 /Users/myname/.m2 现在我能做到: 但是后来Docker中的linux实现不知道在那里看.我想将linux位置
当您查看 Dockerfile for a maven build时,它包含以下行:
VOLUME /root/.m2

现在,如果这是我的.m2存储库在我的Mac上的地方,这将是很好的 – 但它不是 – 它在

/Users/myname/.m2

现在我能做到:

但是后来Docker中的linux实现不知道在那里看.我想将linux位置映射到mac位置,并将其作为我的vagrant init的一部分.有一些像:

ln /root/.m2 /Users/myname/.m2

我的问题是:如何将docker镜像指向我的.m2目录,以便在mac上的docker中运行maven?

解决方法

How do I point a docker image to my .m2 directory for running maven in docker on a mac?

您更喜欢将主机文件夹(如/Users/myname/.m2)指向容器文件夹(而不是图像)

见“Mount a host directory as a data volume”:

In addition to creating a volume using the -v flag you can also mount a directory from your Docker daemon’s host into a container.

$docker run -d -P --name web -v /Users/myname/.m2:/root/.m2 training/webapp python app.py

This command mounts the host directory,/Users/myname/.m2,into the container at /root/.m2.
If the path /root/.m2 already exists inside the container’s image,the /Users/myname/.m2 mount overlays but does not remove the pre-existing content. Once the mount is removed,the content is accessible again. This is consistent with the expected behavior of the mount command.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读