ADD/COPY案例--自定义镜像tomcat9
1.mkdir -p /root/mydocker/tomcat9
2.touch 1.txt
3.将jdk和tomcat安装包拷贝到目录下
4.创建Dockerfile文件
FROM centos
MAINTAINER yz<yz@126.com>
#宿主机的1.txt文件拷贝到容器/usr/local下
COPY 1.txt /usr/local/cincontainer.txt
#jdk/tomcat
ADD jdk-8u261-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.55.tar.gz /usr/local/
#INSTALL vim
RUN yum install -y vim
#设置WORKDIR
ENV MYDIR /usr/local
WORKDIR $MYDIR
#PATH
ENV JAVA_HOME /usr/local/jdk1.8.0_261
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.55
ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.55
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#port
EXPOSE 8080
#running tamcat
CMD /usr/local/apache-tomcat-8.5.55/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.55/bin/logs/catalina.out
5.构建镜像
docker build -f Dockerfile -t mytomcat9 .
6.运行容器
docker run -d -p 9090:8080 --name mytomcat9 -v /root/mydocker/tomcat9/test:/usr/local/apache-tomcat-8.5.55/webapps/test -v /root/mydocker/tomcat9/logs:/usr/local/apache-tomcat-8.5.55/logs --privileged=true mytomcat9
7.验证
[root@aaa ~/mydocker/tomcat9]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4374713acb0 mytomcat9 "/bin/sh -c '/usr/..." 3 seconds ago Up 1 second 0.0.0.0:9090->8080/tcp mytomcat9
[root@aaa ~/mydocker/tomcat9]# docker exec a4374713acb0 ls -l
total 0
drwxr-xr-x 1 root root 45 Aug 7 03:40 apache-tomcat-8.5.55
drwxr-xr-x 2 root root 6 Apr 11 2018 bin
-rw-r--r-- 1 root root 0 Aug 7 00:42 cincontainer.txt
drwxr-xr-x 2 root root 6 Apr 11 2018 etc
drwxr-xr-x 2 root root 6 Apr 11 2018 games
drwxr-xr-x 2 root root 6 Apr 11 2018 include
drwxr-xr-x 8 10143 10143 273 Jun 18 06:59 jdk1.8.0_261
drwxr-xr-x 2 root root 6 Apr 11 2018 lib
drwxr-xr-x 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x 5 root root 49 May 4 15:35 share
drwxr-xr-x 2 root root 6 Apr 11 2018 src