[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
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。