24

I've seen that on Windows and Mac it's very easy to change the RAM containers are given - you just go into the GUI. But how do you do this on Linux, where it's a CLI instead of a GUI?

The Docker docs mention an -m flag, but this flag doesn't give any response (just prints the entirety of the help output again) so I don't know whether it worked. It also seems specific to containers, whereas I'd like to change the global default.

Lastly, is there a way to check the current default RAM, so I can make sure whatever I do in the end actually worked?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
James Ronald
  • 685
  • 1
  • 6
  • 13

2 Answers2

32

On native Linux, Docker can use all available host memory. It uses a lightweight kernel-based isolation mechanism that generally shares resources like CPU cores and memory (and on modern installations, disk space) using the standard kernel mechanism. There isn't a control or setting to limit or increase this.

On other platforms Docker runs a hidden Linux VM to be able to run a Linux kernel to use these isolation mechanisms, and the Docker Desktop memory control affects the memory allocation for that VM.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • 2
    I see! So what happens when I pass an argument using the `-m` flag on Linux? – James Ronald Jun 30 '20 at 21:59
  • 2
    It sets a memory limit on the cgroup managing the container. It's not too dissimilar from the `ulimit` command, in that it sets a limit enforced by the kernel, but it doesn't specifically partition resources. – David Maze Jun 30 '20 at 22:26
  • The GUI option to configure max resources is now also gone from Windows if you use WSL2. But it can be configured in other ways - see https://stackoverflow.com/questions/62405765/memory-allocation-to-docker-containers-after-moving-to-wsl-2-in-windows – user2347921 Sep 03 '20 at 09:20
11

This is how I "check" the Docker container memory:

Open the linux command shell and -

Step 1: Check what containers are running.

docker ps

Step 2: Note down the 'CONTAINER ID' of the container you want to check and issue the following command:

docker container stats <containerID>

eg:

docker container stats c981

This will give an output like:

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
c981c9482284        registry            0.00%               4.219MiB / 1.944GiB   0.21%               9.66kB / 0B         0B / 0B             14

'MEM USAGE / LIMIT' column will give you the actual memory usage and default memory allocated.

Note : press ctrl+c to come out of the view and back to command prompt.

Praym
  • 2,038
  • 23
  • 21