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

3 simple ways to achieve carousel effects with JS

This article shares 3 methods to achieve the spec...

Detailed explanation of Nginx static file service configuration and optimization

Root directory and index file The root directive ...

The implementation process of extracting oracle data to mysql database

In the migration of Oracle database to MySQL data...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

Application nesting of HTML ul unordered tables

Application nesting of unordered lists Copy code T...

HTML table only displays the outer border of the table

I would like to ask a question. In Dreamweaver, I...

How to use uni-app to display buttons and search boxes in the top navigation bar

Recently, the company is preparing to develop an ...

How to remove the dotted border when clicking a link in FireFox

I encountered several browser compatibility issue...

Example code for implementing 3D Rubik's Cube with CSS

Let's make a simple 3D Rubik's Cube today...

How to remove the underline of a hyperlink using three simple examples

To remove the underline of a hyperlink, you need t...

Detailed example of using js fetch asynchronous request

Table of contents Understanding Asynchrony fetch(...

Analyze MySQL replication and tuning principles and methods

1. Introduction MySQL comes with a replication so...

MySQL quickly inserts 100 million test data

Table of contents 1. Create a table 1.1 Create te...

A brief analysis of MySQL cardinality statistics

1. What is the cardinality? Cardinality refers to...