1

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

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.

MiGo
  • 551
  • 2
  • 7
  • 17

2 Answers2

1

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.

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"]

To your question about how can you use CMD with this, for example like this:

    ENTRYPOINT ["sh", "-c"]
    CMD ["your command with env variable"]

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

Also you could take a look at great page with best practices for writing Dockerfile and ENTRYPOINT instructions specifically.

uraji
  • 11
  • 1
  • 3
  • If you're doing this, skip `ENTRYPOINT` and use `CMD your command etc` without the JSON quoting. (Try `docker run ... ls -lrt /` on your image with this `ENTRYPOINT` setting.) – David Maze Dec 06 '19 at 00:51
0

Two suggestions that complement each other:

If you're COPYing a file into the image, you can give it a fixed name inside the image. That avoids this problem.

WORKDIR /opt/payara
COPY service/war/target/app-emailverification-service-war-${snapshotversion}.war deployments/app-service.war

If you have a particularly long or involved command that you're trying to make be the main container process, wrap it in a shell script. You want to make sure to exec the main container process to avoid some trouble around signal handling (resulting in docker stop pausing for 10 seconds and then hard-killing your actual process).

#!/bin/sh
exec java \
  -jar /opt/payara/payara-micro.jar \
  --deploy /opt/payara/deployments/app-service.war \
  --domainConfig /opt/payara/MICRO-INF/domain/domain.xml \
  --addLibs /opt/payara/ojdbc6.jar
COPY launch.sh ./
RUN chmod +x launch.sh
CMD ["/opt/payara/launch.sh"]

In this second case, it's a shell script, so you can have ordinary shell variable substitutions.

David Maze
  • 130,717
  • 29
  • 175
  • 215