Dockerコンテナのメモリ使用量を制限する

  • Docker Engine 24.0
  • Docker Compose 2.21

Docker

# 100 MB
sudo docker update --memory "100m" "$CONTAINER_ID"
# 1 GB
sudo docker update --memory "1g" "$CONTAINER_ID"
# 制限を解除
sudo docker update --memory "0" "$CONTAINER_ID"

Docker Compose

app:
image: hello-world
deploy:
resources:
limits:
memory: '1g'

参考