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","-Djava.security.egd=file:/dev/./urandom","-jar","/sources-registry.jar"]
EXPOSE 8761

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.

  • How to send node.js logs to Cloudwatch Logs from Elastic Beanstalk Docker application?
  • Jupyter kernel dead
  • could not read Username for 'https://github.com': No such device or address
  • How to use docker in windows 7
  • Can a docker image use executable from the host?
  • How to remove old docker images in continuous integration to save disk space
  • 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","-Djava.security.egd=file:/dev/./urandom","-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
      container?
    3. The main question: Why second Dockerfile is not working? And how I can make it work?

  • How to stop/start logstash service running in docker
  • run “docker run” from crontab
  • Running an executable binary made w/ JET Excelsior in Docker
  • Why did host network.service restart sever communications with all containers?
  • Why not “docker push” only publish the Dockerfile?
  • Why does parse_git_branch fail ONLY in Docker terminal window
  • 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.