[英]Can I copy a directory from within a docker Image in dockerfile?
I am trying to build a simple java web application(not maven) from within my docker file by pulling code from my git server and creating a deployable war.In order to do so I have to copy the classes directory to my WEB-INF Folder .My classes directory is at /usr/app_name/build/classes (in the docker image) and I want to copy it to /usr/app_name/WebContent/WEB-INF/ (within the same image). 我试图通过从git服务器中提取代码并创建可部署的war,从我的docker文件中构建一个简单的Java Web应用程序(而非maven),为此,我必须将classes目录复制到我的WEB-INF文件夹中我的类目录位于/ usr / app_name / build / classes (在docker映像中),我想将其复制到/ usr / app_name / WebContent / WEB-INF / (在同一映像中)。
Here is my docker file: 这是我的docker文件:
FROM maven:3.5-jdk-8 AS buildserver
WORKDIR /usr/app_name
RUN git clone http://uname:pass@git_server_host:git_server_port/scm/tes/app_name.git /usr/app_name
COPY /usr/app_name/build/classes /usr/app_name/WebContent/WEB-INF/
#***#Is there any way to perform above operation***
WORKDIR /usr/app_name/WebContent/WEB-INF/
RUN jar -cvf app_name.war *
FROM tomcat:latest
COPY --from=buildserver /usr/app_name/WebContent/WEB-INF/app_name.war .
EXPOSE 5060
The COPY
command in docker only works for copying files from the docker host machine to the image being built. docker中的
COPY
命令仅适用于将文件从docker主机复制到正在构建的映像。 You can do what you need by just running a cp
command in the image (or using rsync
or some other tool if you have them installed in the container). 您可以通过仅在映像中运行
cp
命令来执行所需的操作(如果在容器中安装了rsync
或其他工具,则可以使用rsync
或其他工具)。 An example of this would be: 例如:
RUN cp -r /usr/app_name/build/classes /usr/app_name/WebContent/WEB-INF/
to copy the contents to /usr/app_name/WebContent/WEB-INF/classes
, or: 将内容复制到
/usr/app_name/WebContent/WEB-INF/classes
,或者:
RUN cp -r /usr/app_name/build/classes/* /usr/app_name/WebContent/WEB-INF/
if you want to copy the content to /usr/app_name/WebContent/WEB-INF directly. 如果要将内容直接复制到/ usr / app_name / WebContent / WEB-INF。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.