This is probably worth a read: Java inside docker: What you must know to not FAIL | Red Hat Developer
Thanks @jaime.bosque that’s a good read.
And seems to confirm what I have been surmising about incorrect memory settings - I see the OP has not made any changes from defaults. If he is running the docker dhis2 as is, then the jvm will be running with a maximum heap of 4G which is possibly not enough to handle any significant load. Its hard to know whether postgresql has also been taking over memory without monitoring.
I think the lessons from all this (regardless of docker) are (i) to learn your java and tomcat and postgresql settings well before trying to configure a production server (ii) be very wary of running unconstrained containers (docker, lxd or anything else). Limiting cpu % and available RAM per container can save you embarrassing down time later.
When planning out the provisioning you really do need to get out a pencil and paper and do some calculations. With 16G RAM, I’d start off by limiting the postgresql container to 8G available RAM to keep it under control. Then set max heap size on java container to be 4G and see if you fare any better. If you do have to allocate more to java then be sure to adjust the limit on the postgresql container. Also be aware what other containers you might be running which could be eating resources. You have to take these into account in your calculations (people often think containers are quite magical and you can run as many as you like in parallel)
Its also worth having some sort of blanket rule when starting any container that never allows one container to use more than 90% of CPU. This can prevent starvation by one container which is going crazy and chewing all the CPU.
Thanks bro. This is a great insight. I might have to take a little refresher course and learn how to do this configuration properly. Possible to recommend increasing the RAM.