制作centos7-ssh镜像配置Dockerfile镜像构建文件
docker run -it centos /bin/bash
yum安装sshd服务器,参考centos7安装ssh 博文
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宿主机端口访问容器
来源:CSDN
作者:lantu0
链接:https://blog.csdn.net/wh0426/article/details/54291125