简体   繁体   中英

COPY and ADD not working in Dockerfile

We have a dockerfile as

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

docker exec -it values /bin/bash

And check the /opt/bitnami/tomcat/data/ directory the war file is not copied.

However we tried the following and when we connected into the docker container the file was copied

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. This is probably the code to the original bitnami/tomcat image, though we are not sure.

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

Any ideas on how to add the file to the tomcat directory

Sameer from Bitnami here.

The issue indeed is with the VOLUME's defined in the Dockerfile . We recognise this as a flaw in our Dockerfile and we are working towards fixing this issue in all our 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 . 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.

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.

For reference, here's one of the notes about defining a volume in the Dockerfile from docker's docs (say that 3 times fast):

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.

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. Hope you find this change helpful.

If you have any further questions, please join our stack community at http://slack.oss.bitnami.com/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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