Skip to content

Add --cpus flag to control cpu resources #27921

@crosbymichael

Description

@crosbymichael

We currently have various flags for managing cpu resources of a container. These flags are still needed for advanced use cases around cpu affinity but for the 90% use case having these multiple flags adds confusing for people.

I propose we add a --cpus flag that takes a float for specifying the number of cpus a user wishes to limit the container to. If a user wishes the container to have 1 cpu then they can simple put --cpus 1.0 as the value and Docker will configure the container correctly. This also will allow users to add partial cpus enabling --cpus 1.5, --cpus 2.3, --cpus 0.5, etc...

Under the hood this will be implemented by cpu-quota and cpu-period on linux and cpu percent on Windows. This will be based on time so that it is possible to allocate percentage of a core on the system.

This will also allow swarm to have a unified configuration option across all platforms for scheduling without having to parse platform specific options or leave users trying to decide if they should use cpu-shares( you never should ) or how cpu quota works and what number they should input.

For people wanting to manage container resources simply then this will really help out and result in a simpler docker run cmdline.

docker run --cpus 2.5 --memory 1g ubuntu bash

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions