简体   繁体   English

spotify dockerfile-maven Dockerfile

[英]spotify dockerfile-maven Dockerfile

I am a docker maven plugin newbie. 我是docker maven插件的新手。

If I understand well, according to Spotify's Dockerfile Maven documentation , one should place the Dockerfile on the root directory of my project (I'm running a spring boot project). 如果我了解得很好,根据Spotify的Dockerfile Maven文档 ,应该将Dockerfile放在我项目的根目录下(我正在运行一个spring boot项目)。

In making a reference to docker's Best practices for writing Dockerfiles : 在参考Docker编写Dockerfile最佳实践时

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. 无论Dockerfile实际位于何处,当前目录中文件和目录的所有递归内容都将作为构建上下文发送到Docker守护程序。 Inadvertently including files that are not necessary for building the image results in a larger build context and larger image size. 疏忽地包含了构建映像所不需要的文件会导致较大的构建上下文和较大的映像大小。

Does that mean that when the Spotify Dockerfile Maven plugin runs the configuration I am exposing my source folder which is sent to docker daemon? 这是否意味着当Spotify Dockerfile Maven插件运行配置时,我正在暴露发送到docker daemon的源文件夹?

Answer 回答

By default, yes the build context will include your source (and your target) directory. 默认情况下,是,构建上下文将包含您的源(和目标)目录。 But, you can add a .dockerignore file that tells it not to do this. 但是,您可以添加一个.dockerignore文件,告诉它不要执行此操作。

If you're not sure what this is, take a look at this tutorial. 如果不确定这是什么,请看一下本教程。

Opinion 意见

IMO: I can imagine scenarios where running docker from maven would be the right thing to do. IMO:我可以想象从maven运行docker是正确的选择。 However, my imagination is very good and there can't be that many shops that are adopting docker but not changing their legacy maven build pipelines. 但是,我的想象力非常好,并且不会有很多采用docker但不更改其传统maven构建管道的商店。

In the majority of cases though, you don't want to do this. 但是,在大多数情况下,您不希望这样做。

Rather, you should use one docker container to build the java artifact and run the unit-tests. 相反,您应该使用一个docker容器来构建Java工件并运行单元测试。 This can then push the artifact to nexus (or whatever repo you're using). 然后,这可以将工件推到联系(或您正在使用的任何回购)。 If this is a webapp or other http service, then you can use a second container to host it and deploy this to an environment to integration test it. 如果这是webapp或其他http服务,则可以使用另一个容器托管它,并将其部署到环境中以对其进行集成测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM