Dockerfile部署Tomcat-9.0.16镜像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dockerfile部署Tomcat-9.0.16镜像相关的知识,希望对你有一定的参考价值。
全步骤:[root@localhost ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y
[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum install -y docker-ce
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service
[root@localhost ~]# tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://w1ogxqvl.mirror.aliyuncs.com"]
}
EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker pull centos:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 5e35e350aded 6 weeks ago 203MB
[root@localhost ~]# ls
anaconda-ks.cfg 模板 图片 下载 桌面 initial-setup-ks.cfg 公共 视频 文档 音乐
[root@localhost ~]# mkdir tomcat
[root@localhost ~]# ls
anaconda-ks.cfg tomcat 模板 图片 下载 桌面
initial-setup-ks.cfg 公共 视频 文档 音乐
`接下来的操作需要先把 jdk-8u91-linux-x64.tar.gz 和 apache-tomcat-9.0.16.tar.gz 两个压缩包 下载下来之后放在 /root/tomcat/ 目录下,再直接解压`
[root@localhost ~]# cd tomcat/
[root@localhost tomcat]# ls
jdk-8u91-linux-x64.tar.gz apache-tomcat-9.0.16.tar.gz
[root@localhost tomcat]# tar zxvf jdk-8u91-linux-x64.tar.gz
[root@localhost tomcat]# tar zxvf apache-tomcat-9.0.16.tar.gz
[root@localhost tomcat]# vim Dockerfile
#基于基础镜像
FROM centos:7
MAINTAINER This is tomcat server
ADD jdk-8u91-linux-x64.tar.gz /root
RUN mv /root/jdk1.8.0_91/ /usr/local/jdk1.8
ENV JAVA_HOME=/usr/local/jdk1.8
ENV CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
ENV PATH=$JAVA_HOME/bin:$PATH
ADD apache-tomcat-9.0.16.tar.gz /root
RUN mv /root/apache-tomcat-9.0.16/ /usr/local/tomcat
RUN ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/bin/;ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/
EXPOSE 8080
ENTRYPOINT /usr/local/tomcat/bin/startup.sh && /bin/bash && tail -f /usr/local/tomcat/logs/catalina.out
[root@localhost tomcat]# docker build -t tomcat:centos
[root@localhost tomcat]# docker run -d -P tomcat:centos
61946199e564f72903d17f70d0d1d14627d7b01e5dc80a808936866c494fc1c5
[root@localhost tomcat]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61946199e564 tomcat:centos "/bin/sh -c ‘/usr/lo…" 12 seconds ago Up 11 seconds 0.0.0.0:32768->8080/tcp quirky_wilbur
#端口为32768
验证:回到宿主机在浏览器中访问CentOS的IP地址的32768端口,看是否可以访问Tomcat主页
以上是关于Dockerfile部署Tomcat-9.0.16镜像的主要内容,如果未能解决你的问题,请参考以下文章