docker项目——上线tomcat网站
项目:
1.使用docker部署tomcat环境
2.上线网站
3.完成访问使用等
第一步、启动基于tomcat镜像的容器
a、导入镜像
[root@localhost ~]# docker load < tomcat-app.tar [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE kubeguide/tomcat-app v1 a29e200a18e9 3 years ago 358MB [root@localhost docker-image]# docker tag kubeguide/tomcat-app:v1 tomcat:latest #改名 [root@localhost docker-image]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest a29e200a18e9 3 years ago 358MB b、启动tomcat镜像 [root@localhost docker-image]# docker run -d -p 8899:8080 tomcat 7e70f15807dadb6c15c2a40a9b494e69648b8706b038d27169e8faa9f131118c [root@localhost docker-image]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7e70f15807da tomcat "catalina.sh run" 8 seconds ago Up 7 seconds 0.0.0.0:8899->8080/tcp jovial_lehmann
第二步、清空容器tomcat网站根目录内容
a、进入容器
[root@localhost docker-image]# docker exec -it 7e70f15807da bash root@7e70f15807da:/usr/local/tomcat# ls LICENSE NOTICE RELEASE-NOTES RUNNING.txt bin conf include lib logs temp webapps work
b、切换至tomcat根目录
root@7e70f15807da:/usr/local/tomcat# cd webapps/ root@7e70f15807da:/usr/local/tomcat/webapps# ls ROOT demo docs examples host-manager manager
c、删除ROOT下所有文件
root@7e70f15807da:/usr/local/tomcat/webapps# cd ROOT/ root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# ls RELEASE-NOTES.txt asf-logo-wide.gif bg-button.png bg-nav-item.png bg-upper.png favicon.ico tomcat-power.gif tomcat.gif tomcat.svg WEB-INF asf-logo.png bg-middle.png bg-nav.png build.xml index.jsp tomcat.css tomcat.png root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# rm -rf * root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# ls root@7e70f15807da:/usr/local/tomcat/webapps/ROOT#
第三步:复制网站文件至tomcat网站根目录并进入容器解压网站内容
[root@localhost /]# docker cp fuhai-jpress-alpha.zip 7e70f15807da:/usr/local/tomcat/webapps/ROOT [root@localhost /]# docker exec -it 7e70f15807da bash root@7e70f15807da:/usr/local/tomcat# cd /usr/local/tomcat/webapps/ROOT root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# ls fuhai-jpress-alpha.zip root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# unzip fuhai-jpress-alpha.zip root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# ls root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# cd jpress/wars/ root@7e70f15807da:/usr/local/tomcat/webapps/ROOT/jpress/wars# cp jpress-web-newest.war ../../ root@7e70f15807da:/usr/local/tomcat/webapps/ROOT/jpress/wars# cd ../.. root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# unzip jpress-web-newest.war root@7e70f15807da:/usr/local/tomcat/webapps/ROOT# ls META-INF WEB-INF fuhai-jpress-alpha.zip jpress jpress-web-newest.war robots.txt static templates
第四步:安装并配置数据库
[root@localhost yum.repos.d]# yum -y install MariaDB-server.x86_64 [root@localhost yum.repos.d]# systemctl restart mysql [root@localhost yum.repos.d]# mysql MariaDB [(none)]> create database tomcat; MariaDB [(none)]> grant all privileges on *.* to tomcat@'%' identified by '123'; MariaDB [(none)]> exit
第五步:浏览器访问网站
第六步:重启docker_tomcat容器
[root@localhost yum.repos.d]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7e70f15807da tomcat "catalina.sh run" 44 minutes ago Up 44 minutes 0.0.0.0:8899->8080/tcp jovial_lehmann [root@localhost yum.repos.d]# docker restart 7e70f15807da 7e70f15807da [root@localhost yum.repos.d]#
作者:无荨
-------------------------------------------
个性签名:学IT,就要做到‘活到老学到老’!
如果觉得这篇文章对你有小小的帮助的话,别忘记点个“推荐”哦!