Skip to content

Latest commit

 

History

History
130 lines (98 loc) · 5.48 KB

File metadata and controls

130 lines (98 loc) · 5.48 KB

tomcat安装挂载

[[toc]]

[toc]

查找tomcat并且下载

root@ubuntu:/tmp/host_data# docker search --help 

Usage:  docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
root@ubuntu:/tmp/host_data# docker search --limit 3  tomcat 
NAME             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat           Apache Tomcat is an open source implementati…   3319      [OK]       
tomee            Apache TomEE is an all-Apache Java EE certif…   96        [OK]       
bitnami/tomcat   Bitnami Tomcat Docker Image                     44                   [OK]
root@ubuntu:/tmp/host_data# docker run -it tomcat /bin/bash

运行

docker run -d -p 8080:8080 --name tomcat01 tomcat

可以使用-P随机分配端口,此时内部和外部端口会不一样

root@ubuntu:/tmp/host_data# docker run -d -P --name tomcat02 tomcat
9e194dbf7ecade3e1261bb836067e6f27c54ef4733ab38a036c1c3a526be5586

我们使用docker ps查看端口号

image-20220511165418337

访问猫首页

为什么上面的tomcat上面啥没有猫猫?

因为这是新版,我们进入tomcat看一下

root@ubuntu:/tmp/host_data# docker ps
CONTAINER ID   IMAGE              COMMAND                  CREATED             STATUS                          PORTS                                         NAMES
9e194dbf7eca   tomcat             "catalina.sh run"        4 minutes ago       Up 4 minutes                    0.0.0.0:49153->8080/tcp, :::49153->8080/tcp   tomcat02
c6b2169449f4   ubuntu             "bash"                   30 minutes ago      Up 30 minutes                                                                 ubuntu2
37d9f24e95a3   ubuntu             "bash"                   About an hour ago   Up About an hour                                                              u1
f19e7fbc3d18   v2fly/v2fly-core   "/usr/bin/v2ray -con…"   About an hour ago   Restarting (2) 21 seconds ago                                                 tcp
root@ubuntu:/tmp/host_data# docker exec -it 9e194dbf7eca /bin/bash
root@9e194dbf7eca:/usr/local/tomcat# ls -l
total 160
-rw-r--r-- 1 root root 18994 Dec  2 22:01 BUILDING.txt
-rw-r--r-- 1 root root  6210 Dec  2 22:01 CONTRIBUTING.md
-rw-r--r-- 1 root root 60269 Dec  2 22:01 LICENSE
-rw-r--r-- 1 root root  2333 Dec  2 22:01 NOTICE
-rw-r--r-- 1 root root  3378 Dec  2 22:01 README.md
-rw-r--r-- 1 root root  6905 Dec  2 22:01 RELEASE-NOTES
-rw-r--r-- 1 root root 16517 Dec  2 22:01 RUNNING.txt
drwxr-xr-x 2 root root  4096 Dec 22 17:07 bin
drwxr-xr-x 1 root root  4096 May 11 09:00 conf
drwxr-xr-x 2 root root  4096 Dec 22 17:06 lib
drwxrwxrwx 1 root root  4096 May 11 09:00 logs
drwxr-xr-x 2 root root  4096 Dec 22 17:07 native-jni-lib
drwxrwxrwx 2 root root  4096 Dec 22 17:06 temp
drwxr-xr-x 2 root root  4096 Dec 22 17:06 webapps
drwxr-xr-x 7 root root  4096 Dec  2 22:01 webapps.dist
drwxrwxrwx 2 root root  4096 Dec  2 22:01 work
root@9e194dbf7eca:/usr/local/tomcat# cd webapps && ls -al
total 12
drwxr-xr-x 2 root root 4096 Dec 22 17:06 .
drwxr-xr-x 1 root root 4096 Dec 22 17:07 ..

这是因为真正有货的是webapps.dist,而web apps里面是空的,此时我们删除并且改名

root@9e194dbf7eca:/usr/local/tomcat/webapps# cd .. &&rm -r webapps
root@9e194dbf7eca:/usr/local/tomcat# mv webapps.dist/ webapps &&cd webapps &&ls -al
total 32
drwxr-xr-x  7 root root 4096 Dec  2 22:01 .
drwxr-xr-x  1 root root 4096 May 11 09:09 ..
drwxr-xr-x  3 root root 4096 Dec 22 17:06 ROOT
drwxr-xr-x 15 root root 4096 Dec 22 17:06 docs
drwxr-xr-x  7 root root 4096 Dec 22 17:06 examples
drwxr-xr-x  6 root root 4096 Dec 22 17:06 host-manager
drwxr-xr-x  6 root root 4096 Dec 22 17:06 manager

image-20220511170245755

如上图,成功了(我设置了映射)


推荐使用的版本

我们的版本是最新的tomcat,其实用不到这么新的,可以删除后重新安装一个旧的

docker run -d -p 8080:8080 --name tomcat03 billygoo/tomcat8-jdk8

查看端口

root@ubuntu:/tmp/host_data# docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED             STATUS                         PORTS                                         NAMES
22e49c33a330   billygoo/tomcat8-jdk8   "catalina.sh run"        15 seconds ago      Up 14 seconds                  0.0.0.0:8080->8080/tcp, :::8080->8080/tcp     tomcat03
9e194dbf7eca   tomcat                  "catalina.sh run"        14 minutes ago      Up 14 minutes                  0.0.0.0:49153->8080/tcp, :::49153->8080/tcp   tomcat02
c6b2169449f4   ubuntu                  "bash"                   40 minutes ago      Up 40 minutes                                                                ubuntu2
37d9f24e95a3   ubuntu                  "bash"                   About an hour ago   Up About an hour                                                             u1
f19e7fbc3d18   v2fly/v2fly-core        "/usr/bin/v2ray -con…"   2 hours ago         Restarting (2) 2 seconds ago                                                 tcp

image-20220511170816781

建议初学者使用后面的方法就行