1. 程式人生 > >Docker自定義映象tomcat

Docker自定義映象tomcat

1.mkdir -p /liyinlong/mydockerfile/tomcat9

2.在上述目錄下touch c.txt

3.將jdk和tomcat安裝的壓縮包拷貝進上一步目錄

apache-tomcat-9.0.8.tar.gz
jdk-8u171-linux-x64.tar.gz

4.在/liyinlong/mydockerfile/tomcat9目錄下新建Dockerfile檔案

FROM   centos
MAINTAINER liyinlong<[email protected]>
#把宿主機當前上下文的c.txt拷貝到容器/usr/local/路徑下
COPY c.txt /usr/local/cincontainer.txt
#把java與tomcat新增到容器中
ADD jdk-8u181-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.11.tar.gz /usr/local/
#安裝vim編輯器
RUN yum -y install vim
#設定工作訪問時候的WORKDIR路徑,登入落腳點
ENV MYPATH /usr/local
WORKDIR $MYPATH
#配置java與tomcat環境變數
ENV JAVA_HOME /usr/local/jdk1.8.0_181
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.11
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.11
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器執行時監聽的埠
EXPOSE 8080
#啟動時執行tomcat
# ENTRYPOINT ["/usr/local/apache-tomcat-9.0.11/bin/startup.sh"]
# CMD ["/usr/local/apache-tomcat-9.0.11/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-9.0.11/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.11/bin/logs/catalina.out

5.構建

[[email protected] tomcat9]# docker build -t  liyinlongtomcat9 .(此處有個點哦,缺少會報錯)

6.run

docker run -d -p 9080:8080 --name myt9 -v /liyinlong/mydockerfile/tomcat9/test:/usr/local/apache-tomcat-9.0.11/webapps/test -v /liyinlong/mydockerfile/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.11/logs --privileged=true liyinlongtomcat9

分步講解:
docker run -d(後臺執行) -p 9080:8080 --name myt9 

-v(新增容器卷) /liyinlong/mydockerfile/tomcat9/test:
/usr/local/apache-tomcat-9.0.11/webapps/test 

-v(新增容器卷) /liyinlong/mydockerfile/tomcat9/tomcat9logs/:
/usr/local/apache-tomcat-9.0.11/logs 

--privileged=true 

liyinlongtomcat9

7.驗證

流覽器開啟:http://192.168.17.132:9080/

docker exec -it containerID /bin/bash

8.總結