How to set the memory size of Docker tomcat

How to set the memory size of Docker tomcat

When installing Tomcat in Docker, Tomcat may overflow its memory when downloading large files or in some cases, so you need to configure the memory size of Tomcat. There are two ways to configure the memory size of Tomcat in Docker:

1. Mount the configuration file in docker

Mount the catalina.sh configuration file of tomcat in docker to the host machine, and then configure the jvm memory size in catalina.sh.

1. You need to re-run a tomcat container (note: the port and container name cannot be repeated)

 docker run -d \
 -v /server/webapps:/usr/local/tomcat/webapps/ \
 -v /server/catalina.sh:/usr/local/tomcat/bin/catalina.sh \
 -v /server/logs/demo:/server/logs/demo \
 -e TZ="Asia/Shanghai" \
 --privileged=true \
 --name demo \
 -p 8080:8080 \
 tomcat8

illustrate:

* -v /server/webapps:/usr/local/tomcat/webapps/ Mount the running directory of the current project to the webapps under tomcat

* -v /server/catalina.sh:/usr/local/tomcat/bin/catalina.sh mounts the host's catalina.sh to the catalina.sh under tomcat in docker

* -v /server/logs/demo:/server/logs/demo mounts logs to the host

* -e TZ="Asia/Shanghai" set time zone

* --privileged=true Set to have real root privileges in the container

* -p 8080:8080 mapping port

* The name of the tomcat8 image

2. Configuration memory in catalina.sh

Add below cygwin=false:

JAVA_OPTS="-server -Xms1024m -Xmx2048m -XX:MaxNewSize=256m -XX:PermSize=128m -XX:MaxPermSize=256m"

-xms initialize heap memory

-xmx Maximum heap memory

2. Directly modify the configuration of catalina.sh of the tomcat container

You can directly enter the container and modify the catalina.sh configuration file of tomcat. However, this method is not recommended because it will be troublesome to hang up again in the future and it is not convenient to configure. If you need to re-run the container, you don’t know the configuration of the memory size in the container.

1. Enter the container

docker exec -it <container_name> /bin/bash

2. Find the catalina.sh configuration file and add configuration (the configuration statement added in the first step is fine)

// If there is no vi command, you need to install vi /usr/local/tomcat/bin/catalina.sh
// Exit the container and restart exit
docker restart <container_name>

Notice:

If you are prompted that the file is a read-only file or that you do not have permission to modify it when modifying Catalina.sh, you need to enter the container with root privileges. The specific method is as follows

Supplement: Obtaining root permissions in Docker containers

There are some operations that often need to be performed in the Docker container, such as suddenly needing to modify a configuration file, etc., but modifying the file requires root permissions. You can refer to the following solution

Usually when modifying files, you will be prompted: read-only file system or Permission denied

1. Mount the configuration file

When running the Docker container, you can copy the configuration file to the host machine, and then when running, load the -v parameter to mount the host machine's configuration file into Docker.

2. Enter the docker container with root privileges

Order:

docker exec -it -u root <container_id> /bin/bash

Notice:

The premise of executing the above command is to add this parameter when running the container: --privileged=true. Otherwise, when entering the container, it will still prompt that you do not have permission to modify.

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • How to install tomcat8 in docker
  • 404 error occurs when accessing the homepage of tomcat started in Docker mode
  • How to install tomcat in docker and deploy the Springboot project war package
  • Steps to deploy multiple tomcat services using DockerFile on Docker container
  • Docker Nginx container and Tomcat container to achieve load balancing and dynamic and static separation operations
  • Detailed steps for installing Tomcat, MySQL and Redis with Docker
  • Why can't I see the access interface for Docker Tomcat?

<<:  Detailed explanation of MySQL phantom reads and how to eliminate them

>>:  Design theory: people-oriented design concept

Recommend

How to implement Vue binding class and binding inline style

Table of contents Binding Class Binding inline st...

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

How to handle the tcp_mark_head_lost error reported by the Linux system

Problem Description Recently, a host reported the...

MySQL Series 14 MySQL High Availability Implementation

1. MHA ​By monitoring the master node, automatic ...

Application of CSS3 animation effects in activity pages

background Before we know it, a busy year is comi...

What are HTML inline elements and block-level elements and their differences

I remember a question the interviewer asked durin...

Detailed analysis of SQL execution steps

Detailed analysis of SQL execution steps Let'...

Explanation of the usage scenarios of sql and various nosql databases

SQL is the main trunk. Why do I understand it thi...

How to add configuration options to Discuz! Forum

Discuz! Forum has many configuration options in th...

Summary of MySQL slow log related knowledge

Table of contents 1. Introduction to Slow Log 2. ...

Docker FAQ

Docker only maps ports to IPv6 but not to IPv4 St...

v-html rendering component problem

Since I have parsed HTML before, I want to use Vu...

HTML uses form tags to implement the registration page example code

Case Description: - Use tables to achieve page ef...