docker搭建tomcat

步骤:

1.下载tomcat 镜像

2.先启动一次tomcat容器 ,把需要的文件拷贝出来

/usr/local/tomcat/webapps
/usr/local/tomcat/conf
/usr/local/tomcat/logs

3.修改对应的配置

4.将本地文件挂载到对应的conf、logs、webapps目录上(就是上面的挂在命令)

下面是具体的docker 命令

docker run -d -e TZ="Asia/Shanghai" -p 8081:8080 --name tomcat -v /opt/tomcat/webapps:/usr/local/tomcat/webapps -v /opt/tomcat/logs:/usr/local/tomcat/logs -v /opt/tomcat/conf:/usr/local/tomcat/conf --privileged=true tomcat

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

下载image

docker pull tomcat

  

拷贝文件

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

docker exec -it tomcat bash

cd /usr/local/tomcat

cp -r webapps.dist/* webapps 容器默认的webapps里边是空的,拷贝进去一个默认的页面,不然会报404错误

exit 退出容器

cd /opt

mkdir tomcat

cd tomcat

docker cp tomcat:/usr/local/tomcat/webapps ./  将容器中的文件拷贝到本地

docker cp tomcat:/usr/local/tomcat/conf ./

docker cp tomcat:/usr/local/tomcat/logs ./

docker rm -f tomcat 删除原来的容器

  

启动容器

docker run -d -e TZ="Asia/Shanghai" -p 8081:8080 --name tomcat -v /opt/tomcat/webapps:/usr/local/tomcat/webapps -v /opt/tomcat/logs:/usr/local/tomcat/logs -v /opt/tomcat/conf:/usr/local/tomcat/conf --privileged=true tomcat

  

浏览器访问:http://192.168.199.230:8081/

 

参考文档:

https://blog.csdn.net/wfq784967698/article/details/103780236

https://developer.aliyun.com/article/673482

你可能感兴趣的:(docker搭建tomcat)