- 时间:2020/1/18 17:34:09
- 浏览:24
- 来源:互联网
记录简单的在Docker 上安装Tomcat
首先我是在云服务器上(Centos系统)安装的Docker,我们需要在https://hub.docker.com/ 上查找Tomcat镜像
[[email protected]_0_17_centos ~]# docker pull tomcat
拉取完官方的Tomcat的镜像后,我们可以在本地镜像列表里查到 REPOSITORY 为 tomcat 的镜像,
[[email protected]_0_17_centos ~]# docker images|grep tomcat
tomcat latest ed94f55483b8 2 weeks ago 507MB
接下来,运行容器
[[email protected]_0_17_centos ~]# docker run -d --name tomcat -p 8080:8080 tomcat:latest
0be1774e1e5e1388663e65b4a5e59d58597072a960684fff3eca009c3e89d054
说明一下:-p 8080:8080:将容器的 8080 端口映射到主机的 8080 端口。
这时候查看docker 正在运行的容器:
[[email protected]_0_17_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0be1774e1e5e tomcat:latest "catalina.sh run" About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp tomcat
这时候已经在运行了,接下来,我们用浏览器访问,
这时候,很奇怪哦,404错误?我这里检查完服务器端口8080已经开放了,接下来,我们进入tomcat的目录:
[[email protected]_0_17_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0be1774e1e5e tomcat:latest "catalina.sh run" 7 minutes ago Up 7 minutes 0.0.0.0:8080->8080/tcp tomcat
[[email protected]_0_17_centos ~]# docker exec -it 0be1774e1e5e /bin/bash
[email protected]:/usr/local/tomcat# ^C
[email protected]:/usr/local/tomcat# ls -l
total 156
-rw-r--r-- 1 root root 19318 Dec 7 19:23 BUILDING.txt
-rw-r--r-- 1 root root 5408 Dec 7 19:23 CONTRIBUTING.md
-rw-r--r-- 1 root root 57011 Dec 7 19:23 LICENSE
-rw-r--r-- 1 root root 1726 Dec 7 19:23 NOTICE
-rw-r--r-- 1 root root 3255 Dec 7 19:23 README.md
-rw-r--r-- 1 root root 7136 Dec 7 19:23 RELEASE-NOTES
-rw-r--r-- 1 root root 16262 Dec 7 19:23 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jan 4 05:07 bin
drwxr-sr-x 1 root root 4096 Jan 18 08:59 conf
drwxr-sr-x 2 root staff 4096 Jan 4 05:07 include
drwxr-xr-x 2 root root 4096 Jan 4 05:06 lib
drwxrwxrwx 1 root root 4096 Jan 18 08:59 logs
drwxr-sr-x 3 root staff 4096 Jan 4 05:07 native-jni-lib
drwxrwxrwx 2 root root 4096 Jan 4 05:06 temp
drwxr-sr-x 2 root staff 4096 Jan 4 05:06 webapps
drwxr-xr-x 7 root root 4096 Dec 7 19:21 webapps.dist
drwxrwxrwx 2 root root 4096 Dec 7 19:19 work
然后查看到里面发现有webapps和webapps.dist两个文件,而wenapps里面没有东西,webapps.dist才是我们要的东西
[email protected]:/usr/local/tomcat# cd ./webapps
[email protected]:/usr/local/tomcat/webapps# ls -l
total 0
所以这里把webapps删掉,把webapps.dist改名为webapps
[email protected]:/usr/local/tomcat# rm -rf webapps
[email protected]:/usr/local/tomcat# mv webapps.dist webapps
改完之后,我们再重新访问:
这时候已经可以访问了。
原文地址:https://www.cnblogs.com/xiaozhang666/p/12382114.html
时间: 2024-10-10 01:43:22