Diogo Santos
Diogo Santos

Reputation: 830

Adding files to a docker instance not working

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!

Upvotes: 0

Views: 48

Answers (1)

debduttoc
debduttoc

Reputation: 314

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

Upvotes: 2

Related Questions