farincz
farincz

Reputation: 5173

Soft memory limit for AWS ECS task defined by docker-compose.yaml

Amazon provides ecs-cli compose command which can set up task definition from docker-compose.yaml

But I am not able to declare memory limits (especially soft one) for such task. Deploy option is not supported.

Skipping unsupported YAML option for service...  option name=deploy 

Is there way how to achieve this with compose? Or is using compose bad idea and it's better to use native task definitions.

update My compose file was requested, here is it

version: '3'

services:
  worker:
    image: 880289074637.dkr.ecr.us-east-1.amazonaws.com/negative-keywords:latest
    env_file: .env
    command: ["celery", "-A", "negmatch", "worker", "-l", "info"]
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
        reservations:
          cpus: '0.25'
          memory: 128M
  web:
    image: 880289074637.dkr.ecr.us-east-1.amazonaws.com/negative-keywords:latest
    env_file: .env
    ports:
      - "80:8000"
    depends_on:
      - "worker"
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
        reservations:
          cpus: '0.25'
          memory: 128M

Upvotes: 3

Views: 2136

Answers (1)

Imran
Imran

Reputation: 6225

You will need to use v2 of docker compose to set the values.

As of today, according docker docs, deploy is meant for swarm mode deployment only.

Looking for options to set resources on non swarm mode containers?

The options described here are specific to the deploy key and swarm mode. If you want to set resource constraints on non swarm deployments, use Compose file format version 2 CPU, memory, and other resource options. If you have further questions, refer to the discussion on the GitHub issue docker/compose/4513.

More info on using v2 vs v3. https://github.com/docker/compose/issues/4513#issuecomment-377311337

Here is sample docker-compose(v2) which sets the soft and hard memory limits on container definition of task. mem_limit is hard limit and mem_reservation is soft limit.

Command -

ecs-cli compose --project-name nginx --file docker-compose.yaml create

Compose File -

version: '2'
services:
  nginx:
    image: "nginx:latest"
    mem_limit: 512m
    mem_reservation: 128m
    cpu_shares: 0
    ports:
      - 80

enter image description here

Upvotes: 1

Related Questions