Docker – misunderstanding about the execution and volume

I have a following Dockerfile in my pet project:

FROM java:8
ADD target/sources-registry-0.0.1-SNAPSHOT.jar sources-registry.jar
RUN bash -c 'touch /sources-registry.jar'
ENTRYPOINT ["java","","-jar","/sources-registry.jar"]

And everything perfectly works – image is created and can be run. Now a bit of description about the project: it is a maven based project and before actually executing the Dockerfile I have to manually run mvn package.

  • composer install failing for unknown reason in travis-ci
  • docker-compose how to run container with bind 1-to-1 ports on ip aliasing interface
  • Rancher and elasticsearch Nest
  • Jenkins using docker: How to run tests?
  • Docker container UUID
  • Error when building the blackbox_exporter Docker image
  • However, if I change the Dokerfile to (because I do not want manually to run mvn package and want to automate it)

    FROM java:8
    RUN ls target
    RUN ./mvnw package
    ADD target/sources-registry-0.0.1-SNAPSHOT.jar sources-registry.jar
    RUN bash -c 'touch /sources-registry.jar'
    #ENTRYPOINT ["java","","-jar","/sources-registry.jar"]
    EXPOSE 8761

    then while execution I get /bin/sh: 1: ./mvnw: not found. However, mvnw is in my project files near the pom.xml.

    Even more if I just do following Dockerfile

    FROM java:8
    RUN ls target/

    then I get ls: cannot access target/: No such file or directory.

    Can someone please explain this behaviour?

    1. I mean why I can actually do something with target folder (first
      Dockerfile) even if does not exist (third Dockerfile)?
    2. How project files (and what files) get copied into a created
    3. The main question: Why second Dockerfile is not working? And how I can make it work?

  • Why does SSH need a passphrase for a passphrase-less key?
  • Docker for dev and production
  • ELK docker access via localhost
  • Clone an image from a docker registry to another
  • How to connect Mysql Docker to other docker in Dockerfile?
  • Docker for Mac - run X11 applications without an active internet connection
  • One Solution collect form web for “Docker – misunderstanding about the execution and volume”

    The ADD command copies over the sources-registry.jar file into the Docker image, so that the first example is able to execute it. If you want to use any other files inside the container, you need to include them in the image as well (using ADD or COPY). See the reference docs for more information

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.