This is a creation in Article, where the information may have evolved or changed.
1,tomcat
Use the alpine environment to pack and install a tomcat environment yourself.
Using the OpenJDK JRE, the goal is to keep the system as small as possible.
Rely on things as little as possible. Building Tomcat requires at least one JRE.
Use of the Openjdk8 JRE is only 106mb. It's already very small.
http://blog.csdn.net/freewebsys/article/details/53744348
Download Tomcat:
http://tomcat.apache.org/download-80.cgi
The latest version of Tomcat is 8.5.9, and Tomcat9 is still in the test, and the production environment uses TOMCAT8, and performance is sufficient.
2, organize the Tomcat
-zxvf apache-tomcat-8.5.9.tar.gz mv apache-tomcat-8.5.9-rf LICENSE NOTICE RELEASE-NOTES RUNNING.txt webapps/* bin/* conf/tomcat-users*
Unzip it first, then remove the clutter from the Tomcat.
What Root,manager,user to prevent others from gaining administrative authority.
Then modify the next service.xml, set root is/access.
<?xml version= "1.0" encoding= "UTF-8"?><Server Port="8005" shutdown="Shutdown"> <Listener className="Org.apache.catalina.startup.VersionLoggerListener"/> <Listener className=" Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener "/> <Listener className=" Org.apache.catalina.core.ThreadLocalLeakPreventionListener "/> <globalnamingresources/> <Service name="Catalina"> <Connector Port="8080" protocol="http/1.1" ConnectionTimeout="20000" redirectport="8443"/> <Engine name="Catalina" defaulthost="localhost" > <Host name="localhost" appBase="WebApps"unpackwars= "true" Autodeploy="true"> <Context docBase="ROOT" path="/"/> <Valve className="Org.apache.catalina.valves.AccessLogValve" Directory ="Logs"prefix= "access_log" suffix=". txt"pattern= "%h%l%T%T%r%s%b%{referer}i%{user-agent}i"/> </Host> </Engine> </Service></Server>
The Jrememoryleakpreventionlistener was removed, and Tomcat's one-hour full GC operation was turned off.
Normal system on-line, memory is generally set very big don't worry about this.
http://gao-xianglong.iteye.com/blog/2171441
3, pack Tomcat
VI Dockerfile
# AlpineLinux open jre 8 & tomcatFROM demo/openjre8-base:1.0# add tomcatRUN mkdir -p /optCOPY tomcat /opt/tomcat# Set environmentENV TOMCAT_HOME /opt/tomcatENV PATH ${PATH}:${TOMCAT_HOME}/binENTRYPOINT ["/opt/tomcat/bin/catalina.sh""run"]
Note that this depends on the mirror of Openjre8, to be ready in advance.
Build:
-t demo/tomcat-base:1.0.
This pack of Tomcat is only 114.8 MB. It's very small.
4, Test start
To create a folder:
-p /data/tomcat/ROOT/WEB-INF"ok"> /data/tomcat/ROOT/indexvi /data/tomcat/ROOT/WEB-INF/web.xml
Write a Web. XML configuration
<?xml version= "1.0" encoding= "UTF-8"? <web-app xmlns = "Http://xmlns.jcp.org/xml/ns/javaee" Xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation =" Http://xmlns.jcp.org/xml/ns/javaee Http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd " version = "3.1" metadata-complete = " True "; </web-app ;
Create a temporary folder, log folder, Temp folder, and set permissions.
When making the Tomcat base package, empty the root folder and add it when the application is to be used later.
mkdir -p /data/tomcat/logsmkdir -p /data/tomcat/tempchcon -Rt svirt_sandbox_file_t /data/tomcat/logschcon -Rt svirt_sandbox_file_t /data/tomcat/temp
To start Tomcat:
-d-p8080:8080-v /data\-v /data-v /data\ --name tomcat-test demo/tomcat-base:1.0
Start Tomcat and bind port 8080, map the directory/data/tomcat/root as the home directory, and map the logs and temp folders.
This gives you a direct look at the Tomcat logs.
#curl localhost:8080/indexok
The test can be accessed successfully.
Go to Docker container to view:
Docker exec-it Tomcat-test Bash
bash-4.3# DF
4, summary
The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53761840 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys
Pay special attention to the point. Some Docker boot time did not drive Tomcat to boot, but the direct exit.
This is not Docker's problem. is because the command used is not correct. To use the catalina.sh run parameter, this command is always executed.
If you use startup.sh, you're on the backstage. Docker thought there was a problem. After the shell executes, it exits directly. Then it can't be executed by-D.
In other words, the use of the entrypoint and CMD commands must be a dead loop that executes the command.
The difference between Entrypoin and cmd is that CMD can be replaced.
If you use Docker run-it demo/tomcat-base Bash This command executes two different packages.
EntryPoint's package tomcat starts, and cmd hits the package, and Tomcat is replaced by the shell. does not start.