0

I have the following snippet in my docker file:

...
 ADD app.war /opt/apache-tomcat-8.5.14/webapps/app.war
...

However, entering the docker image as:

docker exec -it tomcat /bin/sh

and doing an ls to the webapps folder, the file isn't there. The file, in my local OS, windows, it is in the same folder as the dockerfile. Any clue about why this happens?

EDIT: However, using the cp command in my windows cmd, it works correctly after checking in the container.

The dockerfile:

FROM alpine:latest
MAINTAINER Adilson Cesar <[email protected]>

# Expose Web Port
EXPOSE 8080

# Set environment
ENV JAVA_HOME /opt/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
ENV JAVA_PACKAGE server-jre

ENV TOMCAT_VERSION_MAJOR 8
ENV TOMCAT_VERSION_FULL  8.5.14
ENV CATALINA_HOME /opt/tomcat

# Download and install Java
RUN apk --update add openjdk8-jre &&\
    mkdir -p /opt/jdk &&\
    ln -s /usr/lib/jvm/java-1.8-openjdk/bin /opt/jdk

# Download and install Tomcat
RUN apk add --update curl &&\
  curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz &&\
  curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
  md5sum -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
  gunzip -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz | tar -xf - -C /opt &&\
  rm -f apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
  ln -s /opt/apache-tomcat-${TOMCAT_VERSION_FULL} /opt/tomcat &&\
  rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs &&\
  apk del curl &&\
  rm -rf /var/cache/apk/*

 ADD app.war /opt/apache-tomcat-8.5.14/webapps/

# Launch Tomcat on startup
CMD ${CATALINA_HOME}/bin/catalina.sh run

Thanks!

1
  • What command/compose file are you using to run your container? Commented Dec 23, 2018 at 16:33

1 Answer 1

2

Although docker docs suggest otherwise

If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>

Try this by removing the destination filename. It should work.

ADD app.war /opt/apache-tomcat-8.5.14/webapps/

Also, from Docker Best Practices it is advised to use COPY instead of ADD if you're just copying local files and not playing around with remote URLs.

Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD

Sign up to request clarification or add additional context in comments.

2 Comments

It unfortunately, didn't work. I updated the post with my dockerfile.
I tried a simple dockerfile with just the ADD command. It worked. Trying with all the installations now. Let's see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.