Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use mem_limit in docker-compose? and How?

Tags:

docker

fig

mem_limit is supported by docker-compose? How can I test it?

I have a following docker-compose.yml

repository:   image: myregistry/my_nginx_image   mem_limit: 60m   volumes:     - /etc/localtime:/etc/localtime   ports:     - "80:80" 

How can I prove that the container actually does not exceed 60 mb of RAM?

I am using:

  • docker 1.3.1
  • docker-compose 1.1.0
like image 418
Montells Avatar asked Mar 03 '15 16:03

Montells


People also ask

Can we use JSON in docker compose?

Yaml is a superset of json so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the filename to use. In this lab we are going to bringup our same nginx and mysql containers using docker-compose file in json format.

How do I give my docker more RAM?

Set Maximum Memory Access To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.

Do you need Dockerfiles with docker compose?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.


2 Answers

Yes. Memory limitation is supported by docker-compose and value can be set as in your example with "m" for megabytes.

It is possible to check what is the memory limit set for running Docker container using "docker stats" command.

If your container name is "repository_1" then use this command:

docker stats repository_1 

The result of this will be simillar to this one:

CONTAINER       CPU %    MEM USAGE/LIMIT    MEM %     NET I/O repository_1    1.93%    4.609 MiB/60 MiB   7.20%     1.832 KiB/648 B 
like image 74
jozala Avatar answered Sep 19 '22 13:09

jozala


According to documentation, simple

mem_limit: 1000000000 

should be enough. I guess, you should drop "m", and use bytes instead of megabytes.

like image 32
noisy Avatar answered Sep 18 '22 13:09

noisy