Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 309
MilindaD Avatar asked Jun 16 '17 13:06

MilindaD


People also ask

What is ADD and COPY command in Dockerfile?

COPY COMMAND ADD COMMAND. COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. Syntax: COPY <src> <dest>

Should I use add or COPY Dockerfile?

ADD or COPY Consequently, the best use for ADD is local tar file auto-extraction into the image, as in ADD rootfs.tar.xz / . If you have multiple Dockerfile steps that use different files from your context, COPY them individually, rather than all at once.

Which statement is correct regarding COPY and add in Dockerfile?

According to the Dockerfile best practices guide, we should always prefer COPY over ADD unless we specifically need one of the two additional features of ADD. As noted above, using ADD to copy remote files into a Docker image creates an extra layer and increases the file size.


1 Answers

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.

like image 93
Sameer Naik Avatar answered Sep 19 '22 13:09

Sameer Naik