製作tomcat docker映象
阿新 • • 發佈:2018-12-26
製作centos7-ssh映象配置Dockerfile映象構建檔案
docker run -it centos /bin/bash
exit #退出centos docker容器
docker tag 980e0e4c79ec 192.168.161.117:5000/os/centos_sshd #儲存安裝了sshd的映象庫為centos_sshd
docker push 192.168.161.117:5000/os/centos_sshd #提交到本地映象庫
構建dockerfile
mkdir tomct-centos
上傳apache-tomcat-8.5.9.tar.gz demo_web.war jdk1.8.0_45 檔案
vi Dockerfile
#新生成的映象是基於sshd-centos映象
FROM 192.168.161.117:5000/os/centos7-ssh
MAINTAINER by wanghao
WORKDIR /usr/local/src
#安裝wget
RUN yum install -y wget
RUN yum install -y unzip
#下載tomcat原始碼包
#RUN wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.9/bin/apache-tomcat-8.5.9.tar.gz
#從宿主機上覆制JDK資料夾
ADD jdk1.8.0_45 /usr/local/jdk1.8.0_45
ADD apache-tomcat-8.5.9.tar.gz /usr/local/src/
ADD demo_web .war /usr/local/src/
RUN ls /usr/local/src
#配置JDK環境指令碼
RUN touch /etc/profile.d/java.sh
RUN echo "JAVA_HOME=/usr/local/jdk1.8.0_45" >> /etc/profile.d/java.sh
RUN echo "JAVA_BIN=/usr/local/jdk1.8.0_45/bin" >> /etc/profile.d/java.sh
RUN echo "JRE_HOME=/usr/local/jdk1.8.0_45/jre" >> /etc/profile.d/java.sh
RUN echo "PATH=$PATH:/usr/local/jdk1.8.0_45/bin:/usr/local/jdk1.8.0_45/jre/bin" >> /etc/profile.d/java.sh
RUN echo "CLASSPATH=/usr/local/jdk1.8.0_45/jre/lib:/usr/local/jdk1.8.0_45/lib:/usr/local/jdk1.8.0_45/jre/lib/charsets.jar" >> /etc/profile.d/java.sh
#匯入JDK環境
RUN . /etc/profile.d/java.sh
#解壓tomcat原始碼包
#RUN tar -zxvf /usr/local/src/apache-tomcat-8.5.9.tar.gz
RUN mv /usr/local/src/apache-tomcat-8.5.9 /usr/local/tomcat
RUN mv /usr/local/src/demo_web.war /usr/local/tomcat/webapps/
#修改tomcat啟動指令碼
WORKDIR /usr/local/tomcat/bin
RUN cp /usr/local/tomcat/bin/catalina.sh /usr/local/tomcat/bin/catalina.sh.bak
RUN > /usr/local/tomcat/bin/catalina.sh
RUN echo '#!/bin/sh'>> /usr/local/tomcat/bin/catalina.sh
RUN echo "JAVA_HOME=/usr/local/jdk1.8.0_45">> /usr/local/tomcat/bin/catalina.sh
RUN echo "CATALINA_HOME=/usr/local/tomcat" >> /usr/local/tomcat/bin/catalina.sh
RUN grep -v '^#!/bin/sh' catalina.sh.bak >> /usr/local/tomcat/bin/catalina.sh
#啟動tomcat服務
RUN /usr/local/tomcat/bin/catalina.sh start
#複製容器啟動指令碼
ADD run.sh /usr/local/sbin/run.sh
#設定指令碼許可權
RUN chmod 755 /usr/local/sbin/run.sh
CMD ["/usr/local/sbin/run.sh"]
#開放容器的22和8080埠
EXPOSE 8080
EXPOSE 22
run.sh
#!/bin/bash
/usr/sbin/sshd -D &
/usr/local/tomcat/bin/catalina.sh run
構建映象
docker build . -t tomcat_centos_sshd
docker run -it tomcat_centos_sshd /bin/bash #進入tomcat_centos_sshd測試 ,切圖可以看到tomcat的bin目錄
docker run -d -p 10022:22 192.168.161.117:5000/os/centos7-ssh /usr/sbin/sshd -D # 使用非互動方式進行tomcat-sshd,暴露10022宿主機埠訪問容器