DockerコンテナのCPU使用量を制限する

  • Docker Engine 24.0
  • Docker Compose 2.21

Docker

# CPU 1個
sudo docker update --cpus "1" "$CONTAINER_ID"
# CPU 0.01個(最小)
sudo docker update --cpus "0.01" "$CONTAINER_ID"
# 制限を解除
sudo docker update --cpus "0" "$CONTAINER_ID"

Docker Compose

app:
image: hello-world
deploy:
resources:
limits:
cpus: '0.1'

参考