如何使用compose将docker volume装入我的docker项目? [英] How to mount docker volume into my docker project using compose?
问题描述
我发现了一些工作,您将本地.m2文件夹安装到Docker容器中。但这将使构建依赖于本地设置。我想做的是创建一个卷(长实时),并将该卷链接/挂载到Docker内的 .m2
文件夹。这样当我第二次运行Docker版本时,它不会下载所有内容。它不会依赖于环境。
如何使用docker-compose?
不知道你的确切配置,我会使用这样的东西...
2
服务:
maven:
图片:无论
卷:
- m2-repo:/home/foo/.m2/repository
卷:
m2-repo:
名为 m2-repo
的数据卷映射到 /home/foo/.m2/repository
(调整路径有必要的)。数据量可以在Docker Compose项目的上/下/开始/停止状态下生存。
您可以通过运行类似 docker-撰写-v
,这将破坏容器和卷。
I have a Maven project. I'm running my Maven builds inside Docker. But the problem with that is it downloads all of the Maven dependencies every time I run it and it does not cache any of those Maven downloads.
I found some work arounds for that, where you mount your local .m2 folder into Docker container. But this will make the builds depend on local setup. What I would like to do is to create a volume (long live) and link/mount that volume to .m2
folder inside Docker. That way when I run the Docker build for the 2nd time, it will not download everything. And it will not be dependent on environment.
How can I do this with docker-compose?
Without knowing your exact configuration, I would use something like this...
version: "2"
services:
maven:
image: whatever
volumes:
- m2-repo:/home/foo/.m2/repository
volumes:
m2-repo:
This will create a data volume called m2-repo
that is mapped to the /home/foo/.m2/repository
(adjust path as necessary). The data volume will survive up/down/start/stop of the Docker Compose project.
You can delete the volume by running something like docker-compose down -v
, which will destroy containers and volumes.
这篇关于如何使用compose将docker volume装入我的docker项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!