1、准备镜像文件tomcat压缩包,jdk的压缩包
tomcat链接:https://pan.baidu.com/s/1Xpecb-BSGR2sdxSL7FDtBw?pwd=1234
提取码:1234
jdk链接:https://pan.baidu.com/s/1mQHInn27j1I9uuuicBsyAA?pwd=1234
提取码:1234
2、编写dockerfile文件,官方命名 Dockerfile ,build会自动寻找这个文件,就不需要 -f 指定了
FROM centos:7
MAINTAINER wq<123456@qq.com>COPY readme.txt /usr/local/readme.txtADD jdk-8u131-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.75.tar.gz /usr/local/RUN yum install -y vim net-toolsENV MYPATH /usr/local
WORKDIR $MYPATHENV JAVA_HOME /usr/local/jdk1.8.0_131
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.75
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.75
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/binEXPOSE 8080CMD /usr/local/apache-tomcat-9.0.75/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.75/bin/logs/catalina.out
3、构建镜像
[root@wq tomcat]# docker build -t diytomcat .
[+] Building 0.5s (11/11) FINISHED docker:default=> [internal] load build definition from Dockerfile 0.0s=> => transferring dockerfile: 681B 0.0s=> [internal] load .dockerignore 0.0s=> => transferring context: 2B 0.0s=> [internal] load metadata for docker.io/library/centos:7 0.2s=> [1/6] FROM docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e 0.0s=> [internal] load build context 0.0s=> => transferring context: 126B 0.0s=> CACHED [2/6] COPY readme.txt /usr/local/readme.txt 0.0s=> CACHED [3/6] ADD jdk-8u131-linux-x64.tar.gz /usr/local/ 0.0s=> CACHED [4/6] ADD apache-tomcat-9.0.75.tar.gz /usr/local/ 0.0s=> CACHED [5/6] RUN yum install -y vim net-tools 0.0s=> CACHED [6/6] WORKDIR /usr/local 0.0s=> exporting to image 0.0s=> => exporting layers 0.0s=> => writing image sha256:dfa3156617fc4cc29fa298858eaf09dab87afaa5364b7cca8423940957794fad 0.0s=> => naming to docker.io/library/diytomcat 0.0s[root@wq tomcat]# docker images |grep diytomcat
diytomcat latest dfa3156617fc 23 minutes ago 893MB
4、启动镜像
[root@wq tomcat]# docker images |grep diytomcat
diytomcat latest dfa3156617fc 23 minutes ago 893MB
[root@wq tomcat]# docker run -d -p 8040:8080 --name my_tomcat -v /home/wq/tomcat/test:/usr/local/apache-tomcat-9.0.75/webapps/test -v /home/wq/tomcat/tomcat_logs/:/usr/local/apache-tomcat-9.0.75/logs diytomcat
9624ae479e00fdcf54ab047de0e14a9d48d31edde940650e74b9d4b26fe1d160
[root@wq tomcat]#
[root@wq tomcat]# docker ps |grep my_tomcat
9624ae479e00 diytomcat "/bin/sh -c '/usr/lo…" 13 seconds ago Up 12 seconds 0.0.0.0:8040->8080/tcp, :::8040->8080/tcp my_tomcat
5、访问测试
虚拟机需要关闭防火墙,服务器需要允许8040端口通过安全组
[root@wq test]# curl localhost:8040<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Apache Tomcat/9.0.75</title><link href="favicon.ico" rel="icon" type="image/x-icon" /><link href="tomcat.css" rel="stylesheet" type="text/css" /></head><body><div id="wrapper"><div id="navigation" class="curved container"><span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span><span id="nav-hosts"><a href="/docs/">Documentation</a></span><span id="nav-config"><a href="/docs/config/">Configuration</a></span><span id="nav-examples"><a href="/examples/">Examples</a></span><span id="nav-wiki"><a href="https://cwiki.apache.org/confluence/display/TOMCAT/">Wiki</a></span><span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span><span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span><br class="separator" /></div><div id="asf-box"><h1>Apache Tomcat/9.0.75</h1></div><div id="upper" class="curved container"><div id="congrats" class="curved container"><h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2></div><div id="notice"><img id="tomcat-logo" src="tomcat.svg" alt="[tomcat logo]" /><div id="tasks"><h3>Recommended Reading:</h3><h4><a href="/docs/security-howto.html">Security Considerations How-To</a></h4><h4><a href="/docs/manager-howto.html">Manager Application How-To</a></h4><h4><a href="/docs/cluster-howto.html">Clustering/Session Replication How-To</a></h4></div></div><div id="actions"><div class="button"><a class="container shadow" href="/manager/status"><span>Server Status</span></a></div><div class="button"><a class="container shadow" href="/manager/html"><span>Manager App</span></a></div><div class="button"><a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a></div></div><br class="separator" /></div><div id="middle" class="curved container"><h3>Developer Quick Start</h3><div class="col25"><div class="container"><p><a href="/docs/setup.html">Tomcat Setup</a></p><p><a href="/docs/appdev/">First Web Application</a></p></div></div><div class="col25"><div class="container"><p><a href="/docs/realm-howto.html">Realms & AAA</a></p><p><a href="/docs/jndi-datasource-examples-howto.html">JDBC DataSources</a></p></div></div><div class="col25"><div class="container"><p><a href="/examples/">Examples</a></p></div></div><div class="col25"><div class="container"><p><a href="https://cwiki.apache.org/confluence/display/TOMCAT/Specifications">Servlet Specifications</a></p><p><a href="https://cwiki.apache.org/confluence/display/TOMCAT/Tomcat+Versions">Tomcat Versions</a></p></div></div><br class="separator" /></div><div id="lower"><div id="low-manage" class=""><div class="curved container"><h3>Managing Tomcat</h3><p>For security, access to the <a href="/manager/html">manager webapp</a> is restricted.Users are defined in:</p><pre>$CATALINA_HOME/conf/tomcat-users.xml</pre><p>In Tomcat 9.0 access to the manager application is split betweendifferent users. <a href="/docs/manager-howto.html">Read more...</a></p><br /><h4><a href="/docs/RELEASE-NOTES.txt">Release Notes</a></h4><h4><a href="/docs/changelog.html">Changelog</a></h4><h4><a href="https://tomcat.apache.org/migration.html">Migration Guide</a></h4><h4><a href="https://tomcat.apache.org/security.html">Security Notices</a></h4></div></div><div id="low-docs" class=""><div class="curved container"><h3>Documentation</h3><h4><a href="/docs/">Tomcat 9.0 Documentation</a></h4><h4><a href="/docs/config/">Tomcat 9.0 Configuration</a></h4><h4><a href="https://cwiki.apache.org/confluence/display/TOMCAT/">Tomcat Wiki</a></h4><p>Find additional important configuration information in:</p><pre>$CATALINA_HOME/RUNNING.txt</pre><p>Developers may be interested in:</p><ul><li><a href="https://tomcat.apache.org/bugreport.html">Tomcat 9.0 Bug Database</a></li><li><a href="/docs/api/index.html">Tomcat 9.0 JavaDocs</a></li><li><a href="https://github.com/apache/tomcat/tree/9.0.x">Tomcat 9.0 Git Repository at GitHub</a></li></ul></div></div><div id="low-help" class=""><div class="curved container"><h3>Getting Help</h3><h4><a href="https://tomcat.apache.org/faq/">FAQ</a> and <a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></h4><p>The following mailing lists are available:</p><ul><li id="list-announce"><strong><a href="https://tomcat.apache.org/lists.html#tomcat-announce">tomcat-announce</a><br />Important announcements, releases, security vulnerability notifications. (Low volume).</strong></li><li><a href="https://tomcat.apache.org/lists.html#tomcat-users">tomcat-users</a><br />User support and discussion</li><li><a href="https://tomcat.apache.org/lists.html#taglibs-user">taglibs-user</a><br />User support and discussion for <a href="https://tomcat.apache.org/taglibs/">Apache Taglibs</a></li><li><a href="https://tomcat.apache.org/lists.html#tomcat-dev">tomcat-dev</a><br />Development mailing list, including commit messages</li></ul></div></div><br class="separator" /></div><div id="footer" class="curved container"><div class="col20"><div class="container"><h4>Other Downloads</h4><ul><li><a href="https://tomcat.apache.org/download-connectors.cgi">Tomcat Connectors</a></li><li><a href="https://tomcat.apache.org/download-native.cgi">Tomcat Native</a></li><li><a href="https://tomcat.apache.org/taglibs/">Taglibs</a></li><li><a href="/docs/deployer-howto.html">Deployer</a></li></ul></div></div><div class="col20"><div class="container"><h4>Other Documentation</h4><ul><li><a href="https://tomcat.apache.org/connectors-doc/">Tomcat Connectors</a></li><li><a href="https://tomcat.apache.org/connectors-doc/">mod_jk Documentation</a></li><li><a href="https://tomcat.apache.org/native-doc/">Tomcat Native</a></li><li><a href="/docs/deployer-howto.html">Deployer</a></li></ul></div></div><div class="col20"><div class="container"><h4>Get Involved</h4><ul><li><a href="https://tomcat.apache.org/getinvolved.html">Overview</a></li><li><a href="https://tomcat.apache.org/source.html">Source Repositories</a></li><li><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></li><li><a href="https://cwiki.apache.org/confluence/display/TOMCAT/">Wiki</a></li></ul></div></div><div class="col20"><div class="container"><h4>Miscellaneous</h4><ul><li><a href="https://tomcat.apache.org/contact.html">Contact</a></li><li><a href="https://tomcat.apache.org/legal.html">Legal</a></li><li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li></ul></div></div><div class="col20"><div class="container"><h4>Apache Software Foundation</h4><ul><li><a href="https://tomcat.apache.org/whoweare.html">Who We Are</a></li><li><a href="https://tomcat.apache.org/heritage.html">Heritage</a></li><li><a href="https://www.apache.org">Apache Home</a></li><li><a href="https://tomcat.apache.org/resources.html">Resources</a></li></ul></div></div><br class="separator" /></div><p class="copyright">Copyright ©1999-2024 Apache Software Foundation. All Rights Reserved</p></div></body></html>
6、发布项目(由于做了卷挂载,可以直接在本地编写项目就可以发布了!)