【发布时间】:2021-03-21 22:19:53
【问题描述】:
我正在尝试使用 maven exec 插件在 maven 构建期间将目录从正在运行的 docker 容器复制到主机。从命令行执行 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) 中运行的。非常感谢您对我所缺少的任何输入,谢谢。
【问题讨论】: