简体   繁体   English

COPY和ADD在Dockerfile中不起作用

[英]COPY and ADD not working in Dockerfile

We have a dockerfile as 我们有一个dockerfile作为

FROM bitnami/tomcat

EXPOSE 8080
EXPOSE 8009

ADD values.war /opt/bitnami/tomcat/data/

Except the values.war file never seems to be added, when we 除了values.war文件似乎永远不会被添加,当我们

docker exec -it values /bin/bash

And check the /opt/bitnami/tomcat/data/ directory the war file is not copied. 并检查/opt/bitnami/tomcat/data/目录中是否未复制war文件。

However we tried the following and when we connected into the docker container the file was copied 但是我们尝试了以下操作,当我们连接到docker容器时,文件被复制了

FROM bitnami/tomcat

EXPOSE 8080
EXPOSE 8009

RUN mkdir -p /var/app
ADD values.war /var/app

So that led us to think that the issue was with the directory and therefore we tried the following 因此,我们认为问题出在目录中,因此我们尝试了以下方法

FROM bitnami/tomcat

EXPOSE 8080
EXPOSE 8009

RUN ls -l /opt/bitnami/tomcat/data/

which gave the output 这给了输出

ls: cannot access /opt/bitnami/tomcat/data/: No such file or directory

when building the image 在构建图像时

We think the issue is because the FROM image bitnami/tomcat uses that directory as a volume or such. 我们认为问题是因为FROM映像bitnami/tomcat将该目录用作卷等。 This is probably the code to the original bitnami/tomcat image, though we are not sure. 这可能是原始bitnami / tomcat图像的代码,尽管我们不确定。

https://github.com/bitnami/bitnami-docker-tomcat/blob/master/9.0/Dockerfile https://github.com/bitnami/bitnami-docker-tomcat/blob/master/9.0/Dockerfile

Any ideas on how to add the file to the tomcat directory 有关如何将文件添加到tomcat目录的任何想法

Sameer from Bitnami here. 来自Bitnami的Sameer。

The issue indeed is with the VOLUME's defined in the Dockerfile . 确实存在于Dockerfile定义的VOLUME问题。 We recognise this as a flaw in our Dockerfile and we are working towards fixing this issue in all our Dockerfiles. 我们认为这是我们的Dockerfile中的缺陷,我们正在努力解决所有Dockerfiles中的这个问题。

This is one of the downsides of defining a volume inside the Dockerfile and the reason why I don't recommend defining them there . 这是在Dockerfile中定义卷的缺点之一,也是我不建议在那里定义它的原因之一。 The behavior of docker is undefined when you attempt to modify files in a volume during a build, it may depend on your version of docker or other external variables, so for portability the best thing is to not do it. 当您在构建期间尝试修改卷中的文件时,未定义docker的行为,这可能取决于您的docker版本或其他外部变量,因此为了便于携带,最好不要这样做。

Since you're working with an image from another party, I'd raise an issue with them to get the line removed (feel free to point them to my blog post for the explanation). 由于你正在处理来自另一方的图像,我会向他们提出一个问题,以便删除该行(请随时将它们指向我的博客文章以获得解释)。 And until that happens, you can checkout their build files from github and change the Dockerfile to build your own version of your base image. 在此之前,您可以从github检出他们的构建文件,并更改Dockerfile以构建您自己的基本映像版本。

For reference, here's one of the notes about defining a volume in the Dockerfile from docker's docs (say that 3 times fast): 作为参考,这里是关于从Docker文档定义Dockerfile中的卷的一个注释(比如说快3倍):

Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded. 从Dockerfile中更改卷:如果任何构建步骤在声明后更改卷内的数据,那么这些更改将被丢弃。

Just want to inform you that the Bitnami Docker images no longer declare VOLUME in the Dockerfile making it easier for our users to extend and customize the docker images. 只想告诉您Bitnami Docker镜像不再在Dockerfile中声明VOLUME ,这样我们的用户就可以更轻松地扩展和自定义docker镜像。 Hope you find this change helpful. 希望您发现此更改有帮助。

If you have any further questions, please join our stack community at http://slack.oss.bitnami.com/ . 如果您有任何其他问题,请访问我们的堆栈社区http://slack.oss.bitnami.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM