Joe
Joe

Reputation: 13101

Docker - memory issue - how to set it to higher value?

Where exactly and how to put in docker-compose.yml file the maximum limit of memory that a docker will use?

version: "3"
services:
  mysql:
    image: "mysql:latest"
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: test
  backend:
    image: "backend:latest"
    ports:
      - 19001:19001
      - 80:80
      - "9001:9000"
    environment:
      DB_USERNAME: test
      DB_PASSWORD: test
      DB_URL: jdbc:mysql://mysql:3306/test
      jdbc_url: jdbc:mysql://mysql:3306
      JAVA_HOME: "/application/jdk8"
    links:
      - "mysql:mysql"

Currently I am running a backend app and it is running out of memory (crashing with memory exception) - this is usage just before the crash:

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
71f94ad4b16c        docker_backend_1    187.58%             1.113GiB / 1.952GiB   57.01%              92.4MB / 61.2MB     147MB / 180MB       73
dc2ec6cca410        docker_web_1        0.38%               95.71MiB / 1.952GiB   4.79%               2.05kB / 0B         59.6MB / 41kB       21
0960ca70127a        docker_mysql_1      0.04%               277.3MiB / 1.952GiB   13.87%              60.2MB / 64.3MB     62.8MB / 3.58GB     51

Upvotes: 6

Views: 22449

Answers (2)

Robert
Robert

Reputation: 36773

Seeing the 1.952GiB limit in the docker stats output, I can guess that the problem is the default configuration that the docker machine has: it is assigned with 2GB of memory by default.

As per in my other answer here, you can see how to configure docker to allow more memory for containers.

Upvotes: 4

Yuankun
Yuankun

Reputation: 7793

Add a deploy.resources section to the service you want to restrain. For example:

version: "3"
services:
  mysql:
    image: "mysql:latest"
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 500M
        reservations:
          cpus: '0.25'
          memory: 200M

See the docs: https://docs.docker.com/compose/compose-file/#resources

Upvotes: 3

Related Questions