I wrote the Dockerfile like the following for tomcat container.
FROM tomcat:9.0
#exec command
RUN apt-get update \
&& apt-get install -y wget \
&& apt-get install -y vim \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
#copy folder : not working
RUN cp -pR /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
#run tomcat
CMD ["catalina.sh","run"]
But "RUN cp **" did not work.
Actually, I did this command in the tomcat container, so this cp command run correctly. Like that.
$ docker exec -it cn-tomcat /bin/bash
root@host_tomcat:/usr/local/tomcat#cp -pR /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
This is the foler in tomcat container.
root@host_tomcat:/usr/local/tomcat# ls -la
total 128
drwxr-xr-x 1 root root 41 Nov 12 01:49 .
drwxr-xr-x 1 root root 20 Oct 22 00:16 ..
-rw-r--r-- 1 root root 18970 Sep 28 13:51 BUILDING.txt
-rw-r--r-- 1 root root 6210 Sep 28 13:51 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Sep 28 13:51 LICENSE
-rw-r--r-- 1 root root 2333 Sep 28 13:51 NOTICE
-rw-r--r-- 1 root root 3372 Sep 28 13:51 README.md
-rw-r--r-- 1 root root 6898 Sep 28 13:51 RELEASE-NOTES
-rw-r--r-- 1 root root 16507 Sep 28 13:51 RUNNING.txt
drwxr-xr-x 2 root root 4096 Oct 22 00:33 bin
drwxr-xr-x 3 1000 1000 254 Nov 12 01:49 conf
drwxr-xr-x 2 root root 4096 Oct 22 00:33 lib
drwxrwxr-x 2 1000 1000 6 Nov 12 01:46 log
drwxrwxrwx 1 root root 177 Nov 12 01:49 logs
drwxr-xr-x 2 root root 159 Oct 22 00:33 native-jni-lib
drwxrwxrwx 2 root root 30 Oct 22 00:33 temp
drwxrwxr-x 3 1000 1000 20 Nov 12 01:59 webapps
drwxr-xr-x 7 root root 81 Sep 28 13:51 webapps.dist
drwxrwxrwx 1 root root 22 Nov 12 01:49 work
root@host_tomcat:/usr/local/tomcat#
What is the problem?
-- add result. --
"docker compose build" is no problem.
[ec2-user@ip-***-***-***-*** pj_tomcat]$ docker compose build
[+] Building 1.6s (7/7) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 753B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/tomcat:9.0 1.5s
=> [1/3] FROM docker.io/library/tomcat:9.0@sha256:**************************************************************** 0.0s
=> => resolve docker.io/library/tomcat:9.0@sha256:**************************************************************** 0.0s
=> CACHED [2/3] RUN apt-get update && apt-get install -y wget && apt-get install -y vim && a 0.0s
=> CACHED [3/3] RUN cp -pR /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:**************************************************************** 0.0s
=> => naming to docker.io/library/pj_tomcat
It is not empty in webapps.dist.
root@host_tomcat:/usr/local/tomcat# pwd
/usr/local/tomcat
root@host_tomcat:/usr/local/tomcat/webapps.dist# ls -la
total 4
drwxr-xr-x 7 root root 81 Sep 28 13:51 .
drwxr-xr-x 1 root root 29 Nov 12 03:59 ..
drwxr-xr-x 3 root root 223 Oct 22 00:33 ROOT
drwxr-xr-x 15 root root 4096 Oct 22 00:33 docs
drwxr-xr-x 7 root root 99 Oct 22 00:33 examples
drwxr-xr-x 6 root root 79 Oct 22 00:33 host-manager
drwxr-xr-x 6 root root 114 Oct 22 00:33 manager
It is empty in webapps. So it is not copied.
root@host_tomcat:/usr/local/tomcat/webapps# pwd
/usr/local/tomcat/webapps
root@host_tomcat:/usr/local/tomcat/webapps# ls -la
total 0
drwxrwxr-x 2 1000 1000 6 Nov 12 03:58 .
drwxr-xr-x 1 root root 29 Nov 12 03:59 ..
There is no cp -pr
in dockerfile:
Option 1:
RUN cp /usr/local/tomcat/webapps.dist /usr/local/tomcat/webapps
In dockerfile: cp
command behaves like the Unix `cp -a command in that directories are copied recursively with permissions preserved if possible.
Option 2:
ADD hom* /mydir/
Option 3:
COPY <SRC> <DEST>
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.