-1

How to specify max cpu and ram in docker compose 3.7.?

My compose file is:

version: "3.7"
services:
  mongodb_container:
    image: mongo:latest
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: psw
      MONGO_INITDB_DATABASE: admin
    ports:
      - 27017:27017
    command: mongod --auth
    volumes:
      - ./data-docker/mongo:/data
javad26897
  • 353
  • 1
  • 4
  • 8
  • 1
    Does this answer your question? [How to specify Memory & CPU limit in docker compose version 3](https://stackoverflow.com/questions/42345235/how-to-specify-memory-cpu-limit-in-docker-compose-version-3) – Domin Apr 25 '20 at 14:08
  • @Domin nnope, its ignoring this resources, In `docker stats` there is a still more memory then I set in docker-compose file – javad26897 Apr 25 '20 at 14:12

1 Answers1

4

You can specify the cpu and memory limit using the deploy option

version: "3.7"
services:
  mongodb_container:
    image: mongo:latest
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: psw
      MONGO_INITDB_DATABASE: admin
    ports:
      - 27017:27017
    command: mongod --auth
    volumes:
      - ./data-docker/mongo:/data
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 150M

But what you need to make that works is to run the docker-compose using --compatibility flag docker-compose --compatibility up --build

Daviid
  • 228
  • 1
  • 6