![](/img/trans.png)
[英]Dockerfile: Copy directory from Windows host to docker container
[英]exec-maven-plugin - copy directory from docker container to host
我正在尝试使用 maven exec 插件将目录从正在运行的 docker 容器复制到 maven 构建期间的主机。 从命令行执行 exec 目标时成功复制目录
mvn exec:exec -Dexec.executable="docker" -Dexec.args="cp $(docker ps -aqf "name=my_container"):/home/user/out ./target/user-reports"
但是失败并出现错误
错误:没有这样的容器:路径:$(docker ps -aqf "name=my_container"):/home/user/out [ERROR] 命令执行失败。 org.apache.commons.exec.ExecuteException:进程退出并出现错误:1(退出值:1)
在 maven 上安装插件,配置如下
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>Copy user reports from container to host</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>cp</argument>
<argument>$(docker ps -aqf "name=my_container"):/home/user/out ./target/user-reports</argument>
</arguments>
</configuration>
</execution>
</plugin>
我尝试在单独的参数标记中分隔主机“./target/user-reports”目录,导致相同的错误。 使用卷挂载不是一个选项,因为构建是在我的 CI 环境中的另一个 docker 容器 (Dind) 中运行的。 非常感谢您对我所缺少的任何输入,谢谢。
Maven 没有在此处运行 shell,因此 shell 结构,如$(...)
命令替换将不起作用。 您还需要确保将每个“单词”分成单独的<argument/>
。
大多数采用容器 ID 的 Docker 命令也采用容器名称。 所以你不需要使用docker ps -qf name=...
来查找容器的ID; 您可以直接在命令中使用它的名称。
这组合应该给你:
<configuration>
<executable>docker</executable>
<arguments>
<argument>cp</argument>
<argument>my_container:/home/user/out</argument>
<argument>./target/user-reports</argument>
</arguments>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.