Docker安装TomCat
拉群镜像
#tomcat:n n为你想要下载的版本
docker pull tomcat:9.0
查看镜像
启动镜像
# -d 以后台方式启动
# -p 将容器中的tomcat默认端口8080映射到本机的3355端口
# --name 给tomcat容器命名为 mytomcat
docker run -d -p 3355:8080 --name mytomcat tomcat9.0
测试访问
测试访问没有,但是没有显示网页
进入容器内部
# exec 进入正在运行容器内部
# -it 交互式访问
docker exec -it mytomcat /bin/bash
root@b95178a5108a:/usr/local/tomcat# ls
BUILDING.txt NOTICE RUNNING.txt lib temp work
CONTRIBUTING.md README.md bin logs webapps
LICENSE RELEASE-NOTES conf native-jni-lib webapps.dist
#进入webapps
root@b95178a5108a:/usr/local/tomcat# cd webapps
root@b95178a5108a:/usr/local/tomcat/webapps# ls -la
total 4
drwxr-xr-x 2 root root 6 Apr 11 03:31 .
drwxr-xr-x 11 root root 4096 Apr 11 03:31 ..
发现问题,1:linux命令少了,2、webapps东西不全,3:阿里云镜像的原因,默认是最小的镜像,所有不必要的的都剔除掉,保证最小的可运行环境
解决 我们发现Root目录在webapps.dist下面
#将webapps.dist中的所有文件复制到webapps中
cp -r webapps.dist/* webapps
重新测试访问