Docker安装tomcat镜像

Docker 安装tomcat

# 1、下载tomcat镜像
[root@bogon home]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
d6ff36c9ec48: Pull complete 
c958d65b3090: Pull complete 
edaf0a6b092f: Pull complete 
80931cf68816: Pull complete 
bf04b6bbed0c: Pull complete 
8bf847804f9e: Pull complete 
fa776a6e7e37: Pull complete 
586534165c2f: Pull complete 
0f6d126a6962: Pull complete 
9f3317edffb3: Pull complete 
Digest: sha256:9de2415ccf10fe8e5906e4b72eda21649a7a1d0b88e9111f8409062599f3728e
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@bogon home]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tomcat              latest              2ae23eb477aa        6 days ago          647MB
# 启动镜像
[root@bogon home]# docker run -d --name tomcat01 -p 8090:8080 tomcat
5c66dfe280f1eec27af86149d792fc572ce6667134c6fc75a6f50cead4d07c99
# 查询容器
[root@bogon home]# docker ps
CONTAINER ID     IMAGE         COMMAND             CREATED              STATUS              PORTS                    NAMES
5c66dfe280f1     tomcat      "catalina.sh run"   About a minute ago   Up About a minute   0.0.0.0:8090->8080/tcp   tomcat01
# 开放4433端口
[root@bogon home]#  firewall-cmd --zone=public --add-port=4433/tcp --permanent
success
# 重启防火墙
[root@bogon home]# firewall-cmd --reload
success

# 测试访问没有问题

# 进入tomcat容器
[root@bogon home]# docker exec -it tomcat01 /bin/bash
# 查看tomcat所在位置
root@5c66dfe280f1:/usr/local/tomcat# whereis tomcat
tomcat: /usr/local/tomcat
root@5c66dfe280f1:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  native-jni-lib  temp  webapps  webapps.dist  work

# 发现问题 
	1、linux命令少了
	2、webapps下没有文件 阿里云镜像的原因,默认是最小的镜像,所有不必要的都删除了,保证了最小可运行环境
	
# 进入webapp目录 发现没有任何文件
root@5c66dfe280f1:/usr/local/tomcat# cd webapps
root@5c66dfe280f1:/usr/local/tomcat/webapps# ls
root@5c66dfe280f1:/usr/local/tomcat/webapps# 

# 发现文件都在webapps.dist目录下
root@5c66dfe280f1:/usr/local/tomcat# cd ../webapps.dist/
root@5c66dfe280f1:/usr/local/tomcat/webapps.dist# ls
ROOT  docs  examples  host-manager  manager
# 拷贝/webapps.dist目录下的所有文件到webapps下
root@5c66dfe280f1:/usr/local/tomcat# cp -r  webapps.dist/* webapps
root@5c66dfe280f1:/usr/local/tomcat# cd webapps
root@5c66dfe280f1:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager

思考:我们以后不说项目如果每次都要进入容器是不是十分麻烦!我们可以在容器外部提供一个映射路径。webapps,我们在外部放置项目,自动同步到内部就好了

posted @ 2020-08-16 15:11  古城,老巷  阅读(610)  评论(0编辑  收藏  举报