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

Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace rules in HTML In HTML, multiple spaces...

Solution to BT Baota Panel php7.3 and php7.4 not supporting ZipArchive

The solution to the problem that the PHP7.3 versi...

How to use vue-bootstrap-datetimepicker date plugin in vue-cli 3

Demand Background Recently, I plan to use Vue and...

How to import Chinese data into csv in Navicat for SQLite

This article shares with you the specific method ...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...

Detailed Example of MySQL curdate() Function

MySQL CURDATE Function Introduction If used in a ...

How to verify whether MySQL is installed successfully

After MySQL is installed, you can verify whether ...

Tutorial on processing static resources in Tomcat

Preface All requests in Tomcat are handled by Ser...

Use HTML and CSS to create your own warm man "Dabai"

The final result is like this, isn’t it cute… PS:...

mysql security management details

Table of contents 1. Introduce according to the o...

How to add a pop-up bottom action button for element-ui's Select and Cascader

As shown in the figure below, it is a common desi...

Graphic tutorial for installing MySQL 5.6.35 on Windows 10 64-bit

1. Download MySQL Community Server 5.6.35 Downloa...