0

I am using dockerfile maven plugin to build the docker images. In pom.xml file, 3 args will be sent to the dockerfile. I have added my dockerfile here.

ARG PROJECT_BASE_DIR
ARG TOMCAT_JULI_ADAPTER_VERSION
ARG TOMCAT_JULI_VERSION
FROM tomcat:8.0-jre8
ADD ${PROJECT_BASE_DIR}/target/dependency/log4j-1.2.17.jar /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/target/dependency/ojdbc7-12.1.0.2.jar /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/target/dependency/tomcat-extras-juli ${TOMCAT_JULI_ADAPTER_VERSION}.jar /usr/local/tomcat/lib/

ADD ${PROJECT_BASE_DIR}/target/dependency/tomcat-juli-${TOMCAT_JULI_VERSION}.jar /usr/local/tomcat/bin/

ADD ${PROJECT_BASE_DIR}/configuration/log4j.properties /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/configuration/server.xml /usr/local/tomcat/conf/
ADD ${PROJECT_BASE_DIR}/scripts/setenv.sh /usr/local/tomcat/

RUN chmod +x setenv.sh
RUN rm /usr/local/tomcat/conf/logging.properties
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "./setenv.sh" ]

pom.xml file

<configuration>
        <repository>${docker.image.name}</repository>
        <tag>${project.version}</tag>
        <buildArgs>
           <PROJECT_BASE_DIR>${project.basedir}</PROJECT_BASE_DIR>
           <TOMCAT_JULI_VERSION>${tomcat-juli.version}</TOMCAT_JULI_VERSION>
           <TOMCAT_JULI_ADAPTER_VERSION>${tomcat-juli-adapters.version}</TOMCAT_JULI_ADAPTER_VERSION>
         </buildArgs>
 </configuration>

When this is run, It won't take the value in ${TOMCAT_JULI_VERSION} and ${TOMCAT_JULI_ADAPTER_VERSION} but ${PROJECT_BASE_DIR} value is taken. I'm getting following error.

ADD failed: stat /var/lib/docker/tmp/docker-builder537359917/target/dependency/tomcat-extras-juli-.jar: no such file or directory

Pubudu Jayasanka
  • 1,294
  • 4
  • 18
  • 34
  • I believe that this is just a maven-configuration problem. How/where do you set the maven properties `tomcat-juli.version` and `tomcat-juli-adapters.version`? I suspect they are unset. Can you test with hardcoded values? – Fabian Braun Nov 13 '18 at 13:55
  • Additionally: [You shouldn't use ADD, but COPY](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy) in your Dockerfile. Try `COPY ./target/dependency/* /usr/local/tomcat/lib/` to copy your jars. – Fabian Braun Nov 13 '18 at 14:00

0 Answers0