I have a leshan server jar file (to which I have made some changes) obtained by running the maven clean install. I specify that I work in linux and I put this jar file inside a “leshan_docker” folder contained in the desktop. within the same folder there is also a dockerfile to build the server image, and it is written as follows:
FROM openjdk:8-jre-alpine COPY /Desktop/leshan_docker/leshan-server-demo-*.jar /Desktop/leshan_docker/ CMD ["java", "-jar", "/leshan-server-demo-2.0.0-SNAPSHOT.jar"]
but when I go to build through this command:
sudo docker build -f Dockerfile3 -t leshan-server3 .
It reports me the following error:
Sending build context to Docker daemon 12MB Step 1/3 : FROM openjdk:8-jre-alpine ---> f7a292bbb70c Step 2/3 : COPY /Desktop/leshan_docker/leshan-server-demo-*.jar /Desktop/leshan_docker/ COPY failed: no source files were specified
How can I go about solving the problem? Thanks in advance for your answers.
Advertisement
Answer
Your source path with the COPY
command should be relative to the build context. Your build context is in the folder you’re running sudo docker build
in since the final argument you gave was .
. I highly recommend taking a look at the docs.
The destination path for the COPY
command should be relative to the path in your container. What may work now is to move your .jar
to the root directory and run it from there.
So if your jar files are in the same directory you’re running the command in, change it to:
COPY leshan-server-demo-*.jar /
It would be better practice to actually create a new directory in the container to hold your .jar
file to keep your work more organized.