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
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
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?
- I mean why I can actually do something with target folder (first
Dockerfile) even if does not exist (third Dockerfile)?
- How project files (and what files) get copied into a created
- The main question: Why second Dockerfile is not working? And how I can make it work?
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