1

I found several posts and blogs on this but cannot get it to work as expected in my case.

I have a docker compose and I tried to add cpu limits per this blog. Tried:

version: "3"
services:
  shell:
    image: someaddress/executor-blah/main:latest
    cpus: 4
    entrypoint:
      - /bin/bash
    working_dir: /workspace
    volumes:
      - .:/workspace

However when I tried to run this container I got a compose error:

The Compose file './docker-compose.yaml' is invalid because: Unsupported config option for services.shell: 'cpus'

Tried also:

version: "3"
services:
  shell:
    image: someaddress/executor-blah/main:latest
    cpus: 4
    entrypoint:
      - /bin/bash
    working_dir: /workspace
    volumes:
      - .:/workspace
    deploy:
      resources:
        limits:
          cpus: '4'

This time the container composed but when I check on a async loop in my hosts terminal using top > 1, all 8 of my laptops cores are used up by this process.

How can I limit a container to, in this case, 4 cores?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • Do you have 8 cores or 4 cores/8th? If you use default CSF scheduler, use the `cpuset` parameter. More details here: https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler – Daniel Hornik Jan 22 '21 at 18:46
  • @DanielHornik aha! I did this `cat /proc/cpuinfo | grep cores` and it says I have 4 cores and not 8, so no wonder they were all lighting up. – Doug Fir Jan 22 '21 at 18:58
  • Hm, but even setting cores to '2' still results in 4 cores being used – Doug Fir Jan 22 '21 at 19:01
  • 1
    `deploy:` isn't supported in non-Swarm mode. But if you set `version: '2.4'`, then [`cpus:`](https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources) is a supported configuration key and should do what you want. – David Maze Jan 22 '21 at 21:01

0 Answers0