在docker中使用tomcat
在docker hub中拉取tomcat:8.5.46-jdk8-openjdk镜像。在docker官方的镜像仓库docker hub中搜索tomcat的容器镜像,这里直接选择的容器镜像为:tomcat:8.5.46-jdk8-openjdk。可以正常访问到网页测试内容时,说明tomcat容器已经正常运行了。检查本地Docker服务状态,确保Docker服务正常运行。检查tomcat容器的运行状态
检查本地操作系统版本:
[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环境
1. 检查本地Docker服务
检查本地Docker服务状态,确保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
2. 检查Docker版本
检查Docker版本
[root@server001 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.22
API version: 1.41
Go version: go1.18.9
Git commit: 3a2c30b
Built: Thu Dec 15 22:30:24 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.22
API version: 1.41 (minimum version 1.12)
Go version: go1.18.9
Git commit: 42c8b31
Built: Thu Dec 15 22:28:33 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.14
GitCommit: 9ba4b250366a5ddde94bb7c9d1def331423aa323
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
四、搜索docker hub中的tomcat镜像
在docker官方的镜像仓库docker hub中搜索tomcat的容器镜像,
这里直接选择的容器镜像为:tomcat:8.5.46-jdk8-openjdk
[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镜像
在docker hub中拉取tomcat:8.5.46-jdk8-openjdk镜像。
[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容器
使用docker-cli快速创建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.查看Tomcat容器状态
检查tomcat容器的运行状态,确保容器的正常启动。
[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.编辑网页内容
编辑一个测试index.html网页文件。
[root@node tomcat]# cd data/
[root@node data]# echo hello > index.html
2.访问tomcat网页
访问地址:http://140.143.163.109:7090/
可以正常访问到网页测试内容时,说明tomcat容器已经正常运行了。
更多推荐
所有评论(0)