如何在ENTRYPOINT dockerfile中访问构建args [英] How to access build args in ENTRYPOINT dockerfile
问题描述
我正在尝试基于payara dockerimage在payara micro中部署应用程序,并且我需要在ENTRYPOINT(基本上我想以ENTRYFORM访问构建args)exec形式中传递一个论据快照版本,因为ENTRYPOINT的exec形式是首选:我的docker文件如下:
I am trying to deploy an app in payara micro based on payara dockerimage and I need to pass one arguement snapshotversion in ENTRYPOINT(basically i want to access the build args in ENTRYFORM) exec form, as exec form of ENTRYPOINT is preferred: my docker file is as follows:
FROM payara/micro:5.193.1
ARG snapshotversion
ENV snapshotvs=$snapshotversion
RUN jar xf payara-micro.jar
COPY /service/war/target/app-emailverification-service-war-${snapshotversion}.war ${DEPLOY_DIR}/
COPY ojdbc6.jar ${PAYARA_HOME}/
COPY --chown=payara domain.xml /opt/payara/MICRO-INF/domain/domain.xml
RUN cd /opt/payara/MICRO-INF/domain && ls -lrt
#ENTRYPOINT ["java", "-jar", "/opt/payara/payara-micro.jar", "--deploy", "/opt/payara/deployments/app-service-war-$snapshotvs.war", "--domainConfig", "/opt/payara/MICRO-INF/domain/domain.xml","--addLibs", "/opt/payara/ojdbc6.jar"]
ENTRYPOINT java -jar /opt/payara/payara-micro.jar --deploy /opt/payara/deployments/app-service-war-$snapshotvs.war --domainConfig /opt/payara/MICRO-INF/domain/domain.xml --addLibs /opt/payara/ojdbc6.jar
注释的ENTRYPOINT不起作用.容器日志显示无效部署.我在这里想念什么?另外,我该如何使用CMD.有人可以举一个例子.
The commented ENTRYPOINT does not work. Container logs says invalid deployment. What am i missing here? Also how can I use CMD with this. Can someone post an example.
推荐答案
注释行不起作用,因为它是 ENTRYPOINT
的 exec 形式,但不能不要调用shell(/bin/sh -c
),因此不会发生变量替换.
The commented line doesn't work, because it is an exec form of ENTRYPOINT
, which doesn't invoke shell (/bin/sh -c
), so variable substitution doesn't happening.
如果要使用 exec 格式和环境变量,则需要直接指定它:
If you want to use an exec form and environment variables you need to specify it directly:
ENTRYPOINT ["sh", "-c", "your command with env variable"]
关于如何与此一起使用 CMD
的问题,例如:
To your question about how can you use CMD
with this, for example like this:
ENTRYPOINT ["sh", "-c"]
CMD ["your command with env variable"]
您提到,您想在 ENTRYPOINT
指令中使用build args.这实际上是不可能的,因为 ARG
和 ENV
都没有在 ENTRYPOINT
或 CMD
中扩展: https://docs.docker.com/engine/reference/builder/#scope
You mentioned, that you want to use build args in ENTRYPOINT
instruction. It's not really possible, because nor ARG
nor ENV
are expanded in ENTRYPOINT
or CMD
: https://docs.docker.com/engine/reference/builder/#environment-replacement, https://docs.docker.com/engine/reference/builder/#scope
此外,您还可以查看具有最佳做法的出色页面用于专门编写Dockerfile和 ENTRYPOINT
指令.
Also you could take a look at great page with best practices for writing Dockerfile and ENTRYPOINT
instructions specifically.
这篇关于如何在ENTRYPOINT dockerfile中访问构建args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!