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

2019-03-10 23:11发布

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

标签: docker fig
3条回答
相关推荐>>
2楼-- · 2019-03-10 23:40

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
查看更多
乱世女痞
3楼-- · 2019-03-10 23:50

You can find how configure docker to limit resources (CPU & MEMORY) and how test your restrictions in this post written last year: resource-management-in-docker.

查看更多
倾城 Initia
4楼-- · 2019-03-10 23:53

According to fig documentation, simple

mem_limit: 1000000000

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

查看更多
登录 后发表回答