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

标签 linux macos maven docker vagrant

当您查看 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)指向 container 文件夹(不是图像)

参见“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.

关于linux - 如何将 docker 镜像指向我的 .m2 目录,以便在 mac 上的 docker 中运行 maven?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234088/

相关文章:

linux - 验证 IP 是否存在于文件中

linux - xargs 用于管道 ls 命令的输出

java - mvn jetty :run failing Caused by: java. lang.RuntimeException : Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil. 类

java - 运行 exec :java 时如何注册 SPI 实现

linux - 批量文件夹重命名

c++ - boost ASIO socket 是否自动使用多个网络接口(interface)?有效率的?如果没有,怎么办?

objective-c - 如何在 OS X 下从 Applescript 调用 Cocoa 方法

macos - 在 Mac 10.12 (Sierra) 上安装 Caffe 时出错 "symbol(s) not found for architecture x86_64"

objective-c - LLDB 摘要字符串 - 如何使它们在 Xcode session 中持久存在

JAVA支持平台 "Dependent"的概念?