21

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?

1
  • If you're using docker-compose you can limit resources consumed using the ymal config.
    – frozenOne
    Jun 30, 2020 at 6:57

2 Answers 2

28

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.

3
  • 2
    I see! So what happens when I pass an argument using the -m flag on Linux? Jun 30, 2020 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, 2020 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 stackoverflow.com/questions/62405765/… Sep 3, 2020 at 9:20
10

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.

2
  • 15
    No, the question was how to CHANGE the memory, not how to view it.
    – juergi
    Jan 29, 2021 at 15:38
  • 1
    @juergi There's a second question in the post, which means it should probably be closed for "needs focus." Feb 16, 2022 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.