tomcat支持自主应用并对外开放端口:
1、制作Dockerfile
以centos为基础,远程ssh登录:新建Dockerfile,编辑如下:
FROM tomcat MAINTAINER ****************** ADD web.xml /usr/local/tomcat/webapps/manager/WEB-INF/ ADD tomcat-users.xml /usr/local/tomcat/conf/ ADD server.xml /usr/local/tomcat/conf/ ADD catalina.sh /usr/local/tomcat/bin/ RUN chmod +x /usr/local/tomcat/bin/catalina.sh ADD ******.war /usr/local/tomcat/webapps/ RUN echo "Asia/shanghai" > /etc/timezone EXPOSE 8080
此处提交了一个******.war的应用,其它server.xml等文件则用于后续使得tomcat可登陆后台;
并且改变了时区
2、我们制作一个yz tag 的镜像:
# docker build -t tomcat:yz . Sending build context to Docker daemon 80.58 MB Sending build context to Docker daemon Step 0 : FROM tomcat latest: Pulling from tomcat 2e05a52ffd47: Pull complete 9fdaeae348bb: Pull complete 67d05086af43: Pull complete 2e9d1ec89d66: Pull complete 1afb0d51eee0: Pull complete 5cb24a57fa37: Pull complete 110c2f290b04: Pull complete 966dcd51a14f: Pull complete 8a57ce404f1b: Pull complete e1b97b980d07: Pull complete 548f21c48132: Pull complete 3e93be06ad38: Pull complete 3e2882dd7e87: Pull complete 4ef5a14c7b39: Pull complete fca011d2612a: Pull complete 119ddf0db1a7: Pull complete 1b8329afb263: Pull complete 1b8329afb263: Pulling fs layer 6d1ae97ee388: Already exists tomcat:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:6880839ca278600ea2a853455dd73c8ec8db9c0860d4aafc4a2b8b4d23dcdd85 Status: Downloaded newer image for tomcat:latest ---> 1b8329afb263 Step 1 : MAINTAINER ****************** ---> Running in 18c800bbf944 ---> f526d4086617 Removing intermediate container 18c800bbf944 Step 2 : ADD web.xml /usr/local/tomcat/webapps/manager/WEB-INF/ ---> ee852f920b73 Removing intermediate container 8803896bc055 Step 3 : ADD tomcat-users.xml /usr/local/tomcat/conf/ ---> 4d749dd1c611 Removing intermediate container bb651ecd1588 Step 4 : ADD server.xml /usr/local/tomcat/conf/ ---> be14c5521112 Removing intermediate container 891d6c70b689 Step 5 : ADD catalina.sh /usr/local/tomcat/bin/ ---> e73227bf617a Removing intermediate container 34069fcf1241 Step 6 : RUN chmod +x /usr/local/tomcat/bin/catalina.sh ---> Running in b7b5d5123ec5 ---> fa85b8df4062 Removing intermediate container b7b5d5123ec5 Step 7 : ADD *******.war /usr/local/tomcat/webapps/ ---> 8a9c3b048437 Removing intermediate container 104b4652b69d Step 8 : RUN echo "Asia/shanghai" > /etc/timezone ---> Running in 1c6260e3f6ae ---> 9be29399285f Removing intermediate container 1c6260e3f6ae Step 9 : EXPOSE 8080 ---> Running in dc015b13ba50 ---> efa62af7320e Removing intermediate container dc015b13ba50 Successfully built efa62af7320e
每一条命令会执行一个container,依次运行
初始阶段会自动下载tomcat原始镜像,而后复制文件、打开端口等
3、测试制作好的镜像:
docker run -d --name yz-tomcat -p 8080:8080 tomcat:yz
命名为yz-tomcat,对外映射宿主机8080端口。
4、打开网页测试
完美运行
5、测试登录后台
点击红圈中的manage app,使用预设的密码登录(tomcat-users.xml中配置)
OK
结束
时间: 2024-10-05 15:19:36