当您查看 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/