LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 08-23-2018, 10:05 AM   #1
sparkling
LQ Newbie
 
Registered: Apr 2017
Posts: 20

Rep: Reputation: Disabled
Docker copies the files into the destination but deletes existing files


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

Code:
FROM guacamole/guacamole

RUN sed -i 's/redirectPort="8443"/redirectPort="8443" server="" secure="true"/g' /usr/local/tomcat/conf/server.xml \
&& sed -i 's/<Server port="8005" shutdown="SHUTDOWN">/<Server port="-1" shutdown="SHUTDOWN">/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:

Code:
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
Code:
docker build . --no-cache -t mine/guacamole
2) Start the containers and create the services by running:
Code:
docker-compose up --force-recreate -d

Can someone please help?

Thanks
 
Old 08-25-2018, 12:54 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
"If you’re copying in local files to your Docker image, always use COPY because it’s more explicit."
says https://nickjanetakis.com/blog/docke...in-a-dockerile


Quote:
Originally Posted by sparkling View Post
Code:
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
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/web.xml
Do these two work as intended?
Quote:
Originally Posted by sparkling View Post
Code:
COPY server.xml conf/server.xml
ADD tomcat.keystore /usr/local/tomcat/
"COPY vs ADD
Both ADD and COPY are designed to add directories and files to your Docker image in the form of ADD <src>... <dest> or COPY <src>... <dest>. Most resources, including myself, suggest to use COPY.

The reason behind this is that ADD has extra features compared to COPY that make ADD more unpredictable and a bit over-designed. ADD can pull files from url sources, which COPY cannot. ADD can also extract compressed files assuming it can recognize and handle the format. You cannot extract archives with COPY.

The ADD instruction was added to Docker first, and COPY was added later to provide a straightforward, rock solid solution for copying files and directories into your container’s file system.

If you want to pull files from the web into your image I would suggest to use RUN and curl and uncompress your files with RUN and commands you would use on the command line." says https://takacsmark.com/dockerfile-tu...8/#copy-vs-add

Are you building?
ADD'ing without a build directory may be problematic AND
one only need specify the file name in the DEST during a "Copy" operation if the destination filename will be different.
so, try
Code:
ADD ./lib/crowd-auth-filter-1.0.0.jar /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
ADD ./lib/crowd-filter.properties /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/
You have culled the usual docker doc sources?

Have Fun!

Last edited by Habitual; 08-25-2018 at 01:08 PM.
 
Old 08-28-2018, 10:37 AM   #3
sparkling
LQ Newbie
 
Registered: Apr 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
"If you’re copying in local files to your Docker image, always use COPY because it’s more explicit."
says https://nickjanetakis.com/blog/docke...in-a-dockerile




Do these two work as intended?

"COPY vs ADD
Both ADD and COPY are designed to add directories and files to your Docker image in the form of ADD <src>... <dest> or COPY <src>... <dest>. Most resources, including myself, suggest to use COPY.

The reason behind this is that ADD has extra features compared to COPY that make ADD more unpredictable and a bit over-designed. ADD can pull files from url sources, which COPY cannot. ADD can also extract compressed files assuming it can recognize and handle the format. You cannot extract archives with COPY.

The ADD instruction was added to Docker first, and COPY was added later to provide a straightforward, rock solid solution for copying files and directories into your container’s file system.

If you want to pull files from the web into your image I would suggest to use RUN and curl and uncompress your files with RUN and commands you would use on the command line." says https://takacsmark.com/dockerfile-tu...8/#copy-vs-add

Are you building?
ADD'ing without a build directory may be problematic AND
one only need specify the file name in the DEST during a "Copy" operation if the destination filename will be different.
so, try
Code:
ADD ./lib/crowd-auth-filter-1.0.0.jar /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
ADD ./lib/crowd-filter.properties /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/
You have culled the usual docker doc sources?

Have Fun!
Habitual,
Thank you for your reply. I have tried your solution but it still doesn't work. I mean it does add the files where they belong, but then at the same time, it removes all the files in that directory so I am left with two crowd files in the lib directory and only the web.xml in the /usr/local/tomcat/webapps/guacamole/WEB-INF.

Yes, these two lines I had in there work as expected:

Code:
COPY server.xml conf/server.xml
ADD tomcat.keystore /usr/local/tomcat/
But the ones I just added do not work. Per what you suggested, I modified my Dockerfile to:

Code:
FROM guacamole/guacamole

RUN sed -i 's/redirectPort="8443"/redirectPort="8443" server="" secure="true"/g' /usr/local/tomcat/conf/server.xml \
&& sed -i 's/<Server port="8005" shutdown="SHUTDOWN">/<Server port="-1" shutdown="SHUTDOWN">/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/
ADD ./lib/crowd-filter.properties /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
RUN chmod 644 /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/crowd-filter.properties
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/
RUN /usr/local/tomcat/bin/shutdown.sh
RUN /usr/local/tomcat/bin/startup.sh
Any help would be much appreciated.

Last edited by sparkling; 08-28-2018 at 11:18 AM.
 
Old 08-31-2018, 01:35 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
dunno, sorry.
only the stuff you added doesn't work.

good luck
 
Old 09-05-2018, 07:45 AM   #5
sparkling
LQ Newbie
 
Registered: Apr 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
dunno, sorry.
only the stuff you added doesn't work.

good luck
No worries, thank you
 
Old 09-05-2018, 02:43 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Sure.
I think it is
Code:
WORKDIR /usr/local/tomcat
Isn't that directory on the build host where tomcat.local resides?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Meld deletes MRU files upnort Linux - Software 0 11-12-2015 05:44 PM
How to overwrite existing files by using tar command (Remove extra files) Kalibo Linux - Newbie 9 12-26-2013 12:42 AM
cp -u copies old files that already exist in the destination directory terence Linux - General 3 11-08-2012 04:07 PM
[rsync] get the differences between the source files and the existing files djgerbavore Linux - Networking 2 06-04-2008 12:05 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration