我想在docker build中參數化最終的jar文件名。我需要docker-maven-plugin來通過命令行參數傳遞jar文件名。 Maven構建不會在構建圖像時拋出任何錯誤。通過從命令行傳遞jar文件名來構建參數化docker
如果我在dockerfile中硬編碼jar文件名,它工作正常。
Maven的命令搬運工構建:
mvn -X -s settings.xml docker:build -DJAR_FILE_NAME=${filename}
我的搬運工文件:
RUN curl -kfsSL https://example.com/UnlimitedJCEPolicyJDK8/US_export_policy.jar > US_export_policy.jar \
&& curl -kfsSL https://example.com//UnlimitedJCEPolicyJDK8/local_policy.jar > local_policy.jar \
&& mv local_policy.jar ${JAVA_HOME}/jre/lib/security \
&& mv US_export_policy.jar ${JAVA_HOME}/jre/lib/security \
&& rm -rf US_export_policy.jar local_policy.jar
ENV JAVA_KEYSTORE ${JAVA_HOME}/jre/lib/security/cacerts
RUN curl -kfsSL https://example.com/mycert.cer > mycert.cer \
&& ${JAVA_HOME}/bin/keytool -v -importcert -file mycert.cer -keystore ${JAVA_KEYSTORE} -storepass dummy -alias dummy -noprompt \
&& rm mycert.cer
VOLUME /tmp
#ADD myservice-2.0.2-SNAPSHOT.jar app.jar <-hard-coded name works fine
RUN echo "final jar file name"
RUN echo ${JAR_FILE_NAME}
ADD ${JAR_FILE_NAME} app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
我的pom.xml
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.0</version>
<configuration>
<imageName>${docker.image.prefix}/myservice</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>${docker.resource.targetPath}</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
從搬運工構建過程輸出:
Step 6 : VOLUME /tmp
---> Using cache
---> xxxxxxxxx
Step 7 : RUN /bin/bash -c echo JAR_FILE_NAME1 in docker :$JAR_FILE_NAME
---> Using cache
---> xxxxxxxxx
Step 8 : RUN /bin/bash -c echo JAR_FILE_NAME2 in docker :${JAR_FILE_NAME}
---> Using cache
---> xxxxxxxxx
Step 9 : RUN echo $JAR_FILE_NAME
---> Using cache
---> xxxxxxxxx
Step 10 : RUN echo "final jar file name"
---> Using cache
---> xxxxxxxxx
Step 11 : RUN echo ${JAR_FILE_NAME}
---> Using cache
---> xxxxxxxxx
Step 12 : ADD ${JAR_FILE_NAME} app.jar
---> Using cache
---> xxxxxxxxx
Step 13 : RUN bash -c 'touch /app.jar'
---> Using cache
---> xxxxxxxxx
Step 14 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
---> Using cache
---> xxxxxxxxx
Successfully built xxxxxxxxx
[INFO] Built xxx/myservice
輸出同時拉動圖像:
I0603 13:48:32.849159 23106 exec.cpp:132] Version: 0.23.0
I0603 13:48:32.857393 23114 exec.cpp:206] Executor registered on slave 20170523-104056-1453378314-5050-11670-S48
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
Error: Invalid or corrupt jarfile /app.jar
我有一大堆Maven和質量蓋茨的東西在Jenkins CI服務器上運行。此外,基本圖像是應該使用的「自定義」圖像。所以現在不能移出maven! :( – bkrish