Jadan1213
Jadan1213

Reputation: 31

docker-compose not honoring CPU limits

<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

Upvotes: 2

Views: 4510

Answers (1)

Jadan1213
Jadan1213

Reputation: 31

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.

Upvotes: 1

Related Questions