Gnana Gnana - 1 month ago 30
Java Question

Docker jetty container JVM memory allocation

I am new to using Docker and have written a compose file for my application. It utilizes jetty and MySQL DB. I configured JVM memory for Jetty via JAVA_OPTS in the environment parameter. I thought the maximum memory setting for jetty JVM was 1GB. However, When I run the commands below, it shows that jetty has consumed 2 GB. Please help on how to configure the JVM memory for jetty and ensure the same.

docker-compose.yml

my-app:
image: jetty
environment:
JAVA_OPTS: "-Xmx1024m -Xms128m"


Status CMD

docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ")

CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
my-app 0.05% 2.188 GB / 10.56 GB 6.39% 12.66 kB / 1.584 kB 57 MB / 45.06 kB

Answer

You have a typo in your environment variable's name:

my-app:
  image: jetty
 environment:
   JAVA_OPTIONS: "-Xmx1024m -Xms128m"

Regards