如何将Maven注入我的docker图像?

如何将Maven注入我的docker图像?,docker,maven,Docker,Maven,我有一个docker映像,它必须以编程方式编译代码作为运行时算法的一部分。 它使用以下代码: if (!Files.exists(rootPath)) { throw new BoilerplateBuildException(String.format("The directory to compile \"%s\" does not exist.", rootPath == null ? "N/A" : rootPath.toString()));

我有一个docker映像,它必须以编程方式编译代码作为运行时算法的一部分。
它使用以下代码:

 if (!Files.exists(rootPath)) {
            throw new BoilerplateBuildException(String.format("The directory to compile \"%s\" does not exist.", rootPath == null ? "N/A" : rootPath.toString()));
        }

        Path pomPath = Paths.get(rootPath.toString(), "pom.xml");
        if (!Files.exists(pomPath)) {
            throw new BoilerplateBuildException(String.format("The MAVEN pom file \"%s\" does not exist.", pomPath.toString()));
        }

        InvocationRequest request = new DefaultInvocationRequest();
        request.setPomFile( new File( pomPath.toString() ) );
        request.setGoals(Arrays.asList("compile"));
        request.setBaseDirectory(new File(rootPath.toString()));

        Invoker invoker = new DefaultInvoker();
        try {
            invoker.setMavenHome(new File(System.getenv("MAVEN_HOME")));

            InvocationResult result = invoker.execute( request );

            if(result != null && result.getExitCode() != 0){
                throw new BoilerplateBuildException(String.format("Failed to build with maven in path \"%s\" (Check the inner exception for further details).", pomPath.toString()), result.getExecutionException());
            }
        } catch (MavenInvocationException e) {
            throw new RuntimeException(String.format("Failed to build with maven for \"%s\"", pomPath.toString()), e);
        }
使用以下工件

 <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-invoker</artifactId>
            <version>3.0.1</version>
 </dependency>

org.apache.maven.shared
maven调用程序
3.0.1
但这仅仅是一个客户。不是Maven本身。
当然,这在本地开发机器上是可行的,因为我已经在上面安装了Maven但当我的代码作为docker容器运行时,情况就完全不同了

所以我的问题是-我可以将Maven“注入”到我的docker映像中(当然还有它的环境变量,比如
Maven\u HOME
),这样我的代码就可以使用它了吗?

请使用已经安装了java的
Maven
映像。可能,您可以选择希望使用的
maven
java
版本的标记

参考:-

使用maven基本映像,您可以从
Dockerfile
构建映像

参考:-

在容器中,您将能够运行
maven
java
命令