CPU and RAM problems

Hello,
I’m experiencing issues with Docker. When I create a container, it consumes 5-10 GB of RAM and consistently utilizes at least 100% of the CPU. I had the same Java applications running on another server without Docker, where they only consumed 1 GB of RAM and approximately 4-10% CPU each. Here are some additional details about my system:

docker info:

Client: Docker Engine - Community
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 101
  Running: 28
  Paused: 0
  Stopped: 73
 Images: 3034
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc version: v1.1.10-0-g18a0cb0
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-89-generic
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 62.79GiB
 Name: Letux
 ID: 0c9e2a66-e6e6-4c0d-ba72-b334f11e5a0d
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

docker stats:

Are you using resource constraints on the containers?
Java will use up to 1/4 of the memory for heap if you don’t set resource constraints. On old java versions, it even used to ignore the resource constraints and always went up to 1/4 of the host memory, even if a resource constraint was set (and resulted in the container being oom killed).

You should monitor the application to identify what’s actually needed and then set the resource constraints accordingly.

If you compare it to on host operation, you need to compare it to a host that has the exact same resources like your docker host.

Yes, I have applied resource constraints; however, this does not address the underlying issue that the containers consume a significant amount of RAM and CPU. It merely prevents excessive utilization of RAM and CPU, but as a result, the containers and their applications no longer run smoothly.

Given the provided details, there is not much I can say except: java can be tamed inside a container by monitoring and tweaking the resource constraints, and tweaking the jvm parameters.

I have found the problem. However, I still have a question about reserving the CPU utilization of each container. How can I deactivate this reservation?

Docker containers don’t reserve resources by default. If the CPU is used that is used by the application running inside it. If it is different without containers I don’t know why, but the reason is probably something that the application has to do differently. Maybe the reason is not Docker but the machine itself. I have seen apps working differently because of a different CPU and (possibly) CPU opimization module compatibility.

To tell you anything more we should know more about what you run and what the app does exactly, but you can try to run “top” in the container find out which process uses the CPU if there are more then one.