簡體   English   中英

exec-maven-plugin - 將目錄從 docker 容器復制到主機

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM