Score:0

Docker COPY fails with no such file or directory, but i am root and can access the file

es flag

Simple dockerfile like this:

FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY /home/dockeradmin/*.war /usr/local/tomcat/webapps

Third statement fails saying no such file or directory. I am running this as root, inside /root. /home/dockeradmin and *.war file is owned by dockeradmin user, but as root i have access to it.

I can run ls /home/dockeradmin/*.war without any issue.

RUN cp /home/dockeradmin/*.war /usr/local/tomcat/webapps

also fails with cp: cannot stat '/home/dockeradmin/*.war': No such file or directory I can also run stat /home/dockeradmin/*.war without any issue. It has 664 permission, changed to 777, no go still.

If i copy the Dockerfile to the /home/dockeradmin and change the instruction:

COPY ./*.war /usr/local/tomcat/webapps

It works fine.

Not sure why the first option has an issue.

Score:4
jp flag

Docker COPY <src> is interpreted as relative path to the docker build context. See the documentation.

manu muraleedharan avatar
es flag
Yes. this was the issue. All paths in COPY are resolved as relative to where you are running docker build from . So /home/dockeradmin/*.war actually became /root/home/dockeradmin/*.war when running it from root folder. And that path did not exist.
Score:1
pk flag

the destination must ends with /

ie: /usr/local/tomcat/webapps/ is correct, not /usr/local/tomcat/webapps

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.