当您查看Dockerfile for a maven build时,它包含以下行:
VOLUME /root/.m2
@H_502_7@
现在,如果这是我的.m2存储库在我的Mac上的地方,这将是很好的 – 但它不是 – 它在
/Users/myname/.m2
@H_502_7@
现在我能做到:
但是后来Docker中的linux实现不知道在那里看.我想将linux位置映射到mac位置,并将其作为我的vagrant init的一部分.有一些像:
ln /root/.m2 /Users/myname/.m2
@H_502_7@
我的问题是:如何将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@H_502_7@ 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
@H_502_7@
This command mounts the host directory,
/Users/myname/.m2@H_502_7@,into the container at
/root/.m2@H_502_7@.
If the path/root/.m2@H_502_7@ already exists inside the container’s image,the
/Users/myname/.m2@H_502_7@ 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.