Docker COPY and ADD delete all the existing files in the destination directory

Hi,

I have several files in a directory on the host machine which I am trying to copy to the Docker container.

The problem is that the files do get copied to the destination but all the existing files inside the destination directory get removed.

Before adding these new ADD lines to my Dockerfile, I had like 20 jar files in the lib directory, by adding these ADD lines the two crowd files below, all 20 existing jar files get deleted and the directory will now contains only two crowd files which were just copied from the host into the container!

I tried without the user ROOT but it would not copy the server.xml and tomcat.keystore

FROM guacamole/guacamole

RUN sed -i ‘s/redirectPort=“8443”/redirectPort=“8443” server=“” secure=“true”/g’ /usr/local/tomcat/conf/server.xml
&& sed -i ‘s///g’ /usr/local/tomcat/conf/server.xml
&& rm -rf /usr/local/tomcat/webapps/docs/*
&& rm -rf /usr/local/tomcat/webapps/examples/*
&& rm -rf /usr/local/tomcat/webapps/manager/*
&& rm -rf /usr/local/tomcat/webapps/host-manager/*

WORKDIR /usr/local/tomcat
USER root
COPY server.xml conf/server.xml
RUN chmod 660 conf/server.xml
USER root
ADD tomcat.keystore /usr/local/tomcat/
RUN chmod 644 tomcat.keystore
RUN chown root:staff /usr/local/tomcat/tomcat.keystore
ADD ./lib/crowd-auth-filter-1.0.0.jar /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/crowd-auth-filter-1.0.0.jar
ADD ./lib/crowd-filter.properties /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/crowd-filter.properties
RUN chmod 644 /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/crowd-filter.properties
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/web.xml
CMD /usr/local/tomcat/bin/shutdown.sh && /usr/local/tomcat/bin/startup.sh

docker-compose.yml:

version: ‘2’

services:
guacd:
hostname: guacd
image: guacamole/guacd
restart: always
container_name: guacd
mysql:
hostname: mysql
image: mysql:5.7
volumes:
- ./tmp/scripts:/docker-entrypoint-initdb.d
restart: always
container_name: mysql
ports:
- “3306:3306”
environment:
- MYSQL_DATABASE=“guacamole”
- MYSQL_USER=“guacamole”
- MYSQL_PASSWORD=“password”
- MYSQL_ROOT_PASSWORD=“password”
guacamole:
build: .
image: mine/guacamole
restart: always
ports:
- “8443:8443”
links:
- guacd
- mysql
container_name: guacamole
environment:
- GUACD_HOSTNAME=guacd
- GUACAMOLE_HOME=/opt/guacamole-home

volumes:
tmp-scripts:

To get things started:

  1. I build the guacamole image with docker build . --no-cache -t mine/guacamole
  2. Start the containers and create the services by running: docker-compose up --force-recreate -d

Can someone please help?

Thanks

A very friendly bump

Hi @tezarin ! I’ve encountered the same problem, have you found it’s cause? Thank you.

One more friendly ‘up’.

I encounter the same pb here… and it also - AND ONLY!- involves tomcat WEB-INF/libs
I tried to perform the same COPY to another path, and didn’t loose previously exiting file…

EDIT :
And… ok : often, you juste need to tell the problem to understand it. All that I needed were a few hours to allow my brain achieving its start.
Indeed, it doesn’t work for everything that is under tomcat/webapps/<webapp_name>… since it is deployed with the CMD (that will start tomcat). Thus, when I perform my “COPY”, there’s still no such path! Thus, the COPY will create the directory, preventing tomcat to deploy all the libs that come from within the .war file.

Thus, solved by me… and I hope this rare flash of my lucidity will help others!