全步骤:
[[email protected] ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y
[[email protected] ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[[email protected] ~]# yum install -y docker-ce
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# setenforce 0
[[email protected] ~]# systemctl start docker.service
[[email protected] ~]# systemctl enable docker.service
[[email protected] ~]# tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://w1ogxqvl.mirror.aliyuncs.com"]
}
EOF
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# docker pull centos:7
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 5e35e350aded 6 weeks ago 203MB
[[email protected] ~]# ls
anaconda-ks.cfg 模板 图片 下载 桌面 initial-setup-ks.cfg 公共 视频 文档 音乐
[[email protected] ~]# mkdir tomcat
[[email protected] ~]# ls
anaconda-ks.cfg tomcat 模板 图片 下载 桌面
initial-setup-ks.cfg 公共 视频 文档 音乐
`接下来的操作需要先把 jdk-8u91-linux-x64.tar.gz 和 apache-tomcat-9.0.16.tar.gz 两个压缩包 下载下来之后放在 /root/tomcat/ 目录下,再直接解压`
[[email protected] ~]# cd tomcat/
[[email protected] tomcat]# ls
jdk-8u91-linux-x64.tar.gz apache-tomcat-9.0.16.tar.gz
[[email protected] tomcat]# tar zxvf jdk-8u91-linux-x64.tar.gz
[[email protected] tomcat]# tar zxvf apache-tomcat-9.0.16.tar.gz
[[email protected] 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
[[email protected] tomcat]# docker build -t tomcat:centos
[[email protected] tomcat]# docker run -d -P tomcat:centos
61946199e564f72903d17f70d0d1d14627d7b01e5dc80a808936866c494fc1c5
[[email protected] 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主页
原文地址:https://blog.51cto.com/14464303/2461850
时间: 2024-10-03 22:29:25