How to allocate the system resources of docker container
Recently, I talked to some colleagues in Ali about deploying Java applications with Docker. One of the common problems is how to set the memory limit of JVM in the container. If you use the official Java image or Docker image based on Java image, you can easily set the memory parameters of JVM by passing the JAVA_OPTS environment variable. For example, for the official tomcat image, we can execute the following command to start a Tomcat instance with a maximum memory of 5 12M-RM-ejava _ opts ='-xmx512m' Tomcat: 8 In the log, We can clearly find that the setting has taken effect "command line parameters:-xmx512m" 02-apr-201612: 46: 26/Denver dino/Tomcat. It is based on Docker's official Tomcat image, and its startup script will check the memory limit in CGroup and Its code is as follows #! /bin/bashlimit _ in _ bytes = $ (cat/sys/fs/cgroup/memory/memory/Denver dino/Tomcat: 8-auto heap passes the following command. From the log, we can detect that the corresponding JVM parameter has been set to 448 MB (5 12-64) docker log test ... 02-apr-201614:18: 09.870 information [main]. Org.apache.catalina.startup.versionloggerlistener.logcommandlineargument:-xmx448m ... We can also adjust the memory of Java applications conveniently. Docker 1. 10 provides the ability to dynamically modify the container resource limit. However, because the JVM is not aware of the modification of container resources, we still need to restart tomcat to change the JVM's memory settings. For example, we can adjust the container memory limit to1gbdockerupdate-m1024m testdocker restart test by the following command to check the log again. The corresponding maximum JVM heap size has been set to 960mb docker log test ... Information [main] organization Apache. catalina. startup. Version LoggerListener. LogCommandLine parameters:. ...