Tomcat simple containerized

Tomcat container of

Think

  • Problem. 1, Tomcat of the container, Tomcat how to configure the APRconnector

    Tomcat base image has been opened APR.

  • Issue 2, Tomcat is a need to rebuild every time.

    First, if the company has a complete set of process container has run up, then recommended by Dockerfilere-building.

    Second, if only run in the test environment, and is a small-scale use, we can be achieved by mounting. We speak in detail below.

  • Question 3, how Tomcat log processing?

    First, we need to figure out Tomcatwhat logs are generated in the first /usr/local/tomcat/logs/case there is a 5 log

    -rw-r----- 1 root root 12083 8月   5 14:48 catalina.2019-08-05.log
    -rw-r----- 1 root root     0 8月   5 11:23 host-manager.2019-08-05.log
    -rw-r----- 1 root root     0 8月   5 11:23 localhost.2019-08-05.log
    -rw-r----- 1 root root   552 8月   5 14:55 localhost_access_log.2019-08-05.txt
    -rw-r----- 1 root root     0 8月   5 11:23 manager.2019-08-05.log

    This we can mount the directory, so log in to write host the corresponding directory. And these logs Tomcatwill be automatically cut.

    There is a log console log, Dockerthe default log drive is json-log, ultimately wrote /var/lib/docker/containers/container_id/container_id-json.log. We can also be achieved by cutting and compression configuration parameters.

Practical operation

We are here for the test environment, and we do not carry out the project of a container, the container is to allow the use of multiple app on a different Tomcat inside. So easy to manage.

Therefore, we use a host to mount directory (replacing the corresponding update on the war package) to achieve. But here we recommend in the case of conditions by Dockerfilere-building.

Mirroring based Tomcat 8.5.43-jdk8-openjdk

Mount directory

宿主机目录                   挂载至容器的目录
/opt/hbg/logs/             /usr/local/tomcat/logs/
/opt/hbg/webapps/          /usr/local/tomcat/webapps/

Cutting logs

日志的最大文件为50M, 超过就进行切割。  --log-opt max-size=50m
日志文件的最大数量  --log-opt max-file=100
日志文件切割后开启压缩 --log-opt compress=true 

Set the time zone to Shanghai

-e TZ="Asia/Shanghai"

Port Mapping

宿主机   容器主机  配置
81      8080      -p 81:8080 

Run command

docker run  -d  -e TZ="Asia/Shanghai"  --mount  type=bind,src=/opt/hbg/logs/,dst=/usr/local/tomcat/logs/   --mount  type=bind,src=/opt/hbg/webapps/,dst=/usr/local/tomcat/webapps/  --log-opt max-size=50m --log-opt max-file=100 --log-opt compress=true   -p 81:8080  tomcat:8.5.43-jdk8-openjdk

Subsequent updates, we only need to update the /opt/hbg/webapps/war under the package on the line.

Guess you like

Origin www.cnblogs.com/operationhome/p/11322139.html