desktop-linux icon indicating copy to clipboard operation
desktop-linux copied to clipboard

how to get container memory limit in docker container?

Open dufeng1010 opened this issue 3 years ago • 4 comments
trafficstars

  • [x ] I have tried with the latest version of Docker Desktop
  • [x ] I have tried disabling enabled experimental features
  • [ ] I have uploaded Diagnostics
  • Diagnostics ID:

Expected behavior

Actual behavior

Information

  • Linux distro:
  • Distro version:
  • Docker Desktop Version:

Steps to reproduce the behavior

when I run docker with -m 20g parameter, docker container is 20g when I run docker without -m parameter, docker container is host machine's memory. docker stats command can get right memory size.

but when I need deploy a application in docker container, this application need docker container memory size, i read /sys/fs/cgroup/memory/memory.limit_in_bytes, it is 9223372036854771712. If I read /proc/meminfo, it is host machine' memory size. how can I read a container memory size conrrectly?

dufeng1010 avatar Sep 30 '22 09:09 dufeng1010

@thaJeztah is there a way to find the memory limit from inside the container?

aiordache avatar Oct 21 '22 10:10 aiordache

I also want to know how to get it

ChenJhua avatar Jan 04 '23 03:01 ChenJhua

From inside the container do: cat /sys/fs/cgroup/memory.max (note this is for Alpine).

stefanprodan avatar Mar 03 '23 13:03 stefanprodan

There hasn't been any activity on this issue for a long time. If the problem is still relevant, mark the issue as fresh with a /remove-lifecycle stale comment. If not, this issue will be closed in 30 days.

Prevent issues from auto-closing with a /lifecycle frozen comment.

/lifecycle stale

docker-robot[bot] avatar Jun 23 '23 01:06 docker-robot[bot]