2016-12-14 11 views
1

まずはお時間をいただきありがとうございます。 dockerfile内のmavenのコマンドを実行しようとしているイム:DockerfileのMavenのライフサイクル

# Base container contains maven, jdk on ubuntu 
FROM maven:3-jdk-8 
# copy my build config pom file to container 
ADD pom.xml /app/ 
# copy the source file directory to the container 
ADD src/ /app/src/ 
# move the app directory inside container to perform mvn buill 
WORKDIR /app/ 
RUN ["mvn", "dependency:resolve"] 
RUN ["mvn", "verify"] 
# resolve dependency offline as suggested by Nicolas 
#RUN mvn dependency:go-offline 
# build by using maven 
RUN mvn package 

しかしImはプロキシに問題がある:私は私が持っている場合、私はのsettings.xmlを追加する必要がありますが、私は知らないと仮定し

$ docker build -t mavenimagen . 
Sending build context to Docker daemon 124.9 kB 
Step 1 : FROM maven:3-jdk-8 
---> b2ef69e414f5 
Step 2 : ADD pom.xml /app/ 
---> Using cache 
---> 57e5b52fe34b 
Step 3 : ADD src/ /app/src/ 
---> Using cache 
---> ace1a117cb4f 
Step 4 : WORKDIR /app/ 
---> Using cache 
---> da544b2298a1 
Step 5 : RUN mvn dependency:resolve 
---> Running in 26258aec0093 
[INFO] Scanning for projects... 
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.pom 
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-jar-plugin:2.4: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.4 
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-plugin/2.1/maven-shade-plugin-2.1.pom 
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-shade-plugin:2.1: Plugin org.apache.maven.plugins:maven-shade-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-shade-plugin:jar:2.1 
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom 
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5 
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom 

を私のプロジェクトや別のディレクトリのルートに追加する。

挨拶!

答えて

1

正確なプロキシの問題は投稿していませんが、それが何であれ、カスタムsettings.xmlファイル(ADD settings.xml /app/)を入れてMaven(RUN mvn -s settings.xml package)と一緒に使用する必要があります。

複数の呼び出しがある場合は、settings.xml~/.m2/に設定することをお勧めします。そのため、すべてのMaven呼び出しでデフォルトで使用されます。

+0

私はあなたの推薦を試みたが、私は結果を見なかった。私の質問を変更する方法で、私はプロキシで自分の問題を追加しました。あなたの答えとあなたの時間をありがとう:) –

+0

いいえ私はどのMaven呼び出しが問題を引き起こすかを見ます。それは 'RUN mvn dependency:resolve'です。 'RUN mvn -s settings.xml dependency:resolve'に変更するとOKになります。あるいは、複数の場合は、 'settings.xml'ファイルを'〜/ .m2/'に入れてください。 –

0

問題は解決され、問題はプロキシです。

私はdockerfileに

ADD settings.xml /root/.m2/settings.xml 

おかげで、この行を追加する必要がありました!

0

これは、作成しようとしている唯一のアプリケーションですか?そうでない場合は、以下のように2つの画像を作成することをお勧めします。

  • Mavenビルドイメージ:xmlが〜/ .m2に設定されています。このイメージには、ソースコードのボリュームマウントがあるため、複数回使用できます。あなたのCI/CDパイプラインの中で。
  • アプリケーションイメージ:このイメージにはアプリケーションを実行するためのjavaのみがあり、本番環境でもコンテナを実行するために使用できます。

HTH !!!

+0

お返事ありがとうございます!それはとても役に立ちます:) –

関連する問題