spotify dockerfile-maven Dockerfile

spotify dockerfile-maven Dockerfile

我是dockermaven插件新手

如果我理解得很好,根据Spotify's Dockerfile Maven documentation,应该将Dockerfile放在我项目的根目录下(我是运行一个spring引导项目)。

参考docker的Best practices for writing Dockerfiles:

Regardless of where the Dockerfile actually lives, all of the recursive contents of files and directories in the current directory are sent to the Docker daemon as the build context. Inadvertently including files that are not necessary for building the image results in a larger build context and larger image size.

这是否意味着当 Spotify Dockerfile Maven 插件运行配置时,我公开了发送到 docker 守护进程的源文件夹?

回答

默认情况下,是的,构建上下文将包括您的源(和目标)目录。但是,您可以添加一个 .dockerignore 文件,告诉它不要这样做。

如果您不确定这是什么,请查看 this tutorial.

意见

IMO:我可以想象从 maven 中 运行ning docker 是正确的事情的场景。然而,我的想象力非常好,不会有那么多商店采用 docker 但不改变他们遗留的 maven 构建管道。

不过在大多数情况下,您不想这样做。

相反,您应该使用一个 docker 容器来构建 java 工件和 运行 单元测试。然后,这可以将工件推送到 nexus(或您正在使用的任何回购协议)。如果这是一个 webapp 或其他 http 服务,那么您可以使用第二个容器来托管它并将其部署到环境中以对其进行集成测试。