Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to copy a file from one folder in a container to another?

I want to copy my compiled war file to tomcat deployment folder in a Docker container. As COPY and ADD deals with moving files from host to container, I tried

RUN mv /tmp/projects/myproject/target/myproject.war /usr/local/tomcat/webapps/ 

as a modification to the answer for this question. But I am getting the error

mv: cannot stat ΓÇÿ/tmp/projects/myproject/target/myproject.warΓÇÖ: No such file or directory

How can I copy from one folder to another in the same container?

like image 265
Shoreki Avatar asked Nov 08 '22 16:11

Shoreki


1 Answers

You can create a multi-stage build:

https://docs.docker.com/develop/develop-images/multistage-build/

Build the .war file in the first stage and name the stage e.g. build, like that:

FROM my-fancy-sdk as build
RUN my-fancy-build #result is your myproject.war 

Then in the second stage:

FROM my-fancy-sdk as build2
COPY --from=build /tmp/projects/myproject/target/myproject.war /usr/local/tomcat/webapps/ 
like image 131
Roman Weis Avatar answered Nov 15 '22 06:11

Roman Weis