龙空技术网

云原生之使用Docker部署Tomcat

运维成长之路 135

前言:

如今姐妹们对“apachetomcatcentos”可能比较关切,咱们都想要了解一些“apachetomcatcentos”的相关内容。那么小编同时在网络上网罗了一些对于“apachetomcatcentos””的相关文章,希望看官们能喜欢,同学们快快来了解一下吧!

一、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="; BUG_REPORT_URL=";  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:   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 \"... 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 \"... 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网页

#冬日生活打卡季#

标签: #apachetomcatcentos