简体   繁体   English

我可以从dockerfile中的docker映像中复制目录吗?

[英]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.

相关问题 我可以将目录从 docker 区域外的某个位置复制到我的 dockerfile 中吗? - Can I copy a directory from some location outside the docker area to my dockerfile? Docker 将文件从 dockerfile 复制到主机 - Docker copy file to host from within dockerfile 如何将文件夹从 Dockerfile 复制到 docker 镜像? - How to copy folders to docker image from Dockerfile? Dockerfile将新创建的文件添加或复制到docker镜像 - 没有这样的文件或目录 - Dockerfile ADD or COPY newly created file to docker image - no such file or directory Dockerfile:将目录从 Windows 主机复制到 docker 容器 - Dockerfile: Copy directory from Windows host to docker container 如何使用 Dockerfile 将目录从 docker 容器复制到主机? - How to copy a directory from docker container to host using Dockerfile? 如何在Dockerfile中提取Docker映像? - How can I pull a Docker image in a Dockerfile? 无法从Dockerfile构建docker镜像 - Can't build docker image from Dockerfile 如何在ubuntu14.04上从localhost将目录或文件复制到docker镜像? - How can I copy a directory or file to a docker image from localhost on ubuntu14.04? 为什么我不能在 Dockerfile 中运行命令,但我可以在我的 Docker 容器中运行命令? - Why can't I run command in Dockerfile but I can from within the my Docker container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM