2

<EDIT: Docker compose now recognizes and applies the the limits set for cpu and memory in the deploy key. so the below issue no longer applies.>

I'm fairly new to docker and I'm trying to run some minecraft containers, however they don't seem to be honoring the cpu limits I'm setting. As you can see in the commented out portions, i'v also tried using v3. No matter what limit I set, the container shows up to 400% cpu usage in docker stats. It is a 4cpu virtual machine hosted with Oracle, running Ubuntu.

Is there any other way to enforce this limit?

---
version: "2.4"
#version: "3.9"
services:
  mc-cl:
    container_name: mc-crimson
    image: itzg/minecraft-server:java11
    ports:
      - 25566:25565
    volumes:
      - ./data:/data
    environment:
      - TYPE=PAPER
      - VERSION=1.15.2
      - EULA=TRUE
      - MEMORY=1536M
      - GID=1001
      - UID=1001
      - USE_AIKAR_FLAGS=true
    cpus: 1
    mem_limit: 3072M
    mem_reservation: 3072M
#    deploy:
#      resources:
#        limits:
#          cpus: '1'
#          memory: 3072M
#        reservations:
#          cpus: '0.5'
#          memory: 3072M
    restart: unless-stopped

If it's helpful, here's my docker version and docker compose version.

Client: Docker Engine - Community

Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:44:28 2021
OS/Arch: linux/arm64
Context: default
Experimental: true

Server: Docker Engine - Community

Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:05 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

Docker Compose version v2.2.2

Jadan1213
  • 31
  • 7
  • This should help you: https://stackoverflow.com/a/57135933/11895568 – ale917k Jan 23 '22 at 19:42
  • with respect, if 'm not mistaken --compatability up converts v3 to its v2 counterparts. Given that I've explicitly attempted this using v2 formatting. I'm not sure this will work. EDIT: I attempted it anyways, and it had no effect. – Jadan1213 Jan 23 '22 at 19:51
  • That’s incorrect. That solution is so to avoid having to use v2. Make sure you follow each step as he does – ale917k Jan 23 '22 at 20:01
  • "1.20.0 introduces a new --compatibility flag designed to help developers transition to version 3 more easily. When enabled, docker-compose reads the deploy section of each service’s definition and attempts to translate it into the equivalent version 2 parameter. " For the deploy section of the YAML, it does what i stated. I also stated that I wrote the compose file in V2 also, using the V2 tags, and the limits were still not honored, allowing the cpu to max out at 400%. I have no need to write a v3 compose file, but tried it to see if it made a difference. – Jadan1213 Jan 23 '22 at 20:16

1 Answers1

1

So I've managed to fix my own issue. I had a thought, and so I did this by removing docker compose v2 (yaml v3) with

rm ~/.docker/cli-plugins/docker-compose

and installed docker-compose v1.25.0 from the repository with

apt install docker-compose -y

The limits are now being honored when running the container.

123 456 789 0
  • 10,565
  • 4
  • 43
  • 72
Jadan1213
  • 31
  • 7
  • 2
    Just as an aside, here in 2022, with v1.29.2 of docker-compose, you can now use yaml 3.9 and the cpus:0.3 will nicely limit the cpu to 30% without docker swarm or v2.x – blissweb Mar 08 '22 at 23:42
  • I added this to the original post, it's great that it works now in the expected way! Thank you for letting me know. – Jadan1213 Dec 28 '22 at 00:46