1

I am trying to copy a jar file in my dockerfile. whne I run build, I can see the jar under target/dockerbuild. But docker does not see the file and I am getting following error.

 COPY failed: no source files were specified

My docker file has those lines for copy operation:

ENV MY_HOME=/usr/local/myhome
COPY target/dockerbuild/my.jar $MY_HOME

Why it cannot find the jar although it exists under the target.

user1474111
  • 1,356
  • 3
  • 23
  • 47

4 Answers4

1

Verify that in your .dockerignore do not have that path (target) in your exceptions

Luisao
  • 455
  • 2
  • 9
  • 20
1

Your error looks like it could be one of the following:

  • The file doesn't exist in the specified path
  • The path doesn't exist (relative to the build context - if you use 'docker build .' then the specified path must exist relative to the current directory)

Please can you share what you run to build your docker image (so we can see the build context) and also your directory structure

JasonS
  • 235
  • 1
  • 8
0

That error said file target/dockerbuild/my.jar is not exist. The architecture of COPY in Dockerfile is:

COPY {file in your host} {path of target in docker image}
GreenMan
  • 269
  • 1
  • 15
0

I had a very similar situation.

ls target/dockerbuild/my.jar

proofed that the file exists but docker build claimed that no source files were specified. However there also was a tiny hint that I did not notice for some time:

When using COPY with more than one source file, the destination must be a directory and end with a /

Though I only had one file I added the / to the copy destination and the build succeeded.

r-uu
  • 423
  • 1
  • 4
  • 18