云原生之使用Docker部署Tomcat

举报
江湖有缘 发表于 2022/11/02 19:56:23 2022/11/02
【摘要】 云原生之使用Docker部署Tomcat

一、Tomcat介绍

Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。

二、检查本地系统版本

[root@node ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

三、检查本地docker状态

[root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-10-31 03:28:51 CST; 2 days ago
     Docs: https://docs.docker.com
 Main PID: 11884 (dockerd)
    Tasks: 108
   Memory: 2.7G
   CGroup: /system.slice/docker.service
           ├─  2014 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8580 -container-ip 172.29.0.2 -container-port 8080
           ├─  2019 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8580 -container-ip 172.29.0.2 -container-port 8080
           ├─  2674 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8015 -container-ip 172.28.0.2 -container-port 8080
           ├─  2681 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8015 -container-ip 172.28.0.2 -container-port 8080
           ├─  6972 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8380 -container-ip 172.30.0.2 -container-port 8080
           ├─  6977 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8380 -container-ip 172.30.0.2 -container-port 8080
           ├─ 11884 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─ 34936 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.27.0.3 -container-port 80
           ├─ 34950 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8080 -container-ip 172.27.0.3 -container-port 80
           ├─ 69485 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8012 -container-ip 172.17.0.4 -container-port 8012
           ├─ 69490 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8012 -container-ip 172.17.0.4 -container-port 8012
           ├─114721 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9000 -container-ip 172.17.0.2 -container-port 9000
           ├─114726 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9000 -container-ip 172.17.0.2 -container-port 9000
           ├─125344 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5000 -container-ip 172.17.0.3 -container-port 5000
           └─125350 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5000 -container-ip 172.17.0.3 -container-port 5000

Nov 02 15:06:01 node dockerd[11884]: time="2022-11-02T15:06:01.517897381+08:00" level=info msg="Download failed, retrying (1/5): read tc...by peer"
Nov 02 15:06:19 node dockerd[11884]: time="2022-11-02T15:06:19.022710231+08:00" level=info msg="Download failed, retrying (2/5): Get \"https://p...
Nov 02 15:08:06 node dockerd[11884]: time="2022-11-02T15:08:06.444826384+08:00" level=info msg="Download failed, retrying (1/5): read tc...by peer"
Nov 02 15:11:42 node dockerd[11884]: time="2022-11-02T15:11:42.508638954+08:00" level=info msg="Download failed, retrying (3/5): unexpected EOF"
Nov 02 15:16:07 node dockerd[11884]: time="2022-11-02T15:16:07.323488604+08:00" level=info msg="Download failed, retrying (3/5): read tc...by peer"
Nov 02 15:16:34 node dockerd[11884]: time="2022-11-02T15:16:34.836861791+08:00" level=info msg="Download failed, retrying (4/5): Get \"https://p...
Nov 02 15:22:05 node dockerd[11884]: time="2022-11-02T15:22:05.407264707+08:00" level=error msg="Not continuing with pull after error: c...anceled"
Nov 02 15:22:05 node dockerd[11884]: time="2022-11-02T15:22:05.418587813+08:00" level=info msg="Layer sha256:4fc242d58285699eca05db3cc7c...aned up"
Nov 02 15:41:11 node dockerd[11884]: time="2022-11-02T15:41:11.521523907+08:00" level=info msg="Attempting next endpoint for pull after ...gin yet"
Nov 02 15:41:11 node dockerd[11884]: time="2022-11-02T15:41:11.522439588+08:00" level=error msg="Handler for POST /v1.41/images/create r...gin yet"
Hint: Some lines were ellipsized, use -l to show in full.


四、搜索docker hub中的tomcat镜像

[root@node ~]# docker search tomcat
NAME                                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat                                         Apache Tomcat is an open source implementati…   3426      [OK]       
tomee                                          Apache TomEE is an all-Apache Java EE certif…   98        [OK]       
bitnami/tomcat                                 Bitnami Tomcat Docker Image                     47                   [OK]
arm32v7/tomcat                                 Apache Tomcat is an open source implementati…   11                   
arm64v8/tomcat                                 Apache Tomcat is an open source implementati…   8                    
rightctrl/tomcat                               CentOS , Oracle Java, tomcat application ssl…   7                    [OK]
amd64/tomcat                                   Apache Tomcat is an open source implementati…   5                    
jelastic/tomcat                                An image of the Tomcat Java application serv…   4                    
tomcat2111/pisignage-server                    PiSignage Server                                3                    [OK]
oobsri/tomcat8                                 Testing CI Jobs with different names.           2                    
cfje/tomcat-resource                           Tomcat Concourse Resource                       2                    
chenyufeng/tomcat-centos                       tomcat基于centos6的镜像                              1                    [OK]
ppc64le/tomcat                                 Apache Tomcat is an open source implementati…   1                    
appsvc/tomcat                                                                                  1                    
tomcat0823/auto1                                                                               0                    
tomcatengineering/pg_backup_rotated            Clone of martianrock/pg_backup_rotated but w…   0                    
tomcat2111/papercut-mf                         PaperCut MF Application Server                  0                    
softwareplant/tomcat                           Tomcat images for jira-cloud testing            0                    [OK]
misolims/miso-base                             MySQL 5.7 Database and Tomcat 8 Server neede…   0                    
s390x/tomcat                                   Apache Tomcat is an open source implementati…   0                    
semoss/docker-tomcat                           Tomcat, Java, Maven, and Git on top of debian   0                    [OK]
wnprcehr/tomcat                                                                                0                    
secoresearch/tomcat-varnish                    Tomcat and Varnish 5.0                          0                    [OK]
tomcat2111/bitbucket-pipelines-elasticsearch   Elasticsearch for Bitbucket's Pipelines         0                    
tomcat2111/phpredisadmin                       This is a Docker image for phpredisadmin        0                    [OK]

五、下载tomcat镜像

[root@node tomcat]# docker pull tomcat:8.5.46-jdk8-openjdk
8.5.46-jdk8-openjdk: Pulling from library/tomcat
092586df9206: Pull complete 
ef599477fae0: Pull complete 
4530c6472b5d: Pull complete 
d34d61487075: Pull complete 
272f46008219: Pull complete 
12ff6ccfe7a6: Pull complete 
f26b99e1adb1: Pull complete 
21bec9c8ea28: Pull complete 
b8a32f28e27c: Pull complete 
94fdd0ba0430: Pull complete 
Digest: sha256:bb4ceffaf5aa2eba6c3ee0db46d863c8b23b263cb547dec0942e757598fd0c24
Status: Downloaded newer image for tomcat:8.5.46-jdk8-openjdk
docker.io/library/tomcat:8.5.46-jdk8-openjdk



六、创建Tomcat容器

1.创建数据目录

[root@node ~]# mkdir -p /data/tomcat/data 
[root@node ~]# chmod -R 777 /data/tomcat/

2.运行Tomcat容器

[root@node tomcat]# docker run -d  --name my_web --restart always -p 7090:8080 -v /data/tomcat/data:/usr/local/tomcat/webapps/ROOT/   tomcat:8.5.46-jdk8-openjdk
26674fb4896f49f26282b3fe21b484d40017d13fd7cc474db5badf57bdb4a865

3.查看容器状态

[root@node data]# docker ps
CONTAINER ID   IMAGE                                                   COMMAND                  CREATED              STATUS                  PORTS                                             NAMES
26674fb4896f   tomcat:8.5.46-jdk8-openjdk                              "catalina.sh run"        About a minute ago   Up About a minute       0.0.0.0:7090->8080/tcp, :::7090->8080/tcp         my_web


七、访问Tomcat网页

1.编辑网页内容


[root@node tomcat]# cd data/
[root@node data]# echo hello > index.html

2.访问tomcat网页

image.png

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。