If you run docker run –help under the memory section you will find the memory limits available for the containers.

  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)

If you are using docker run you could simple pass in a memory limit as follows:

docker run -v /mnt/d/temp/dockertests/python3/scripts:/scripts python-docker python /scripts/test.py --memory 1024

If you want more details about the command above you can read How To Run Python From Docker. The above command runs a python script and limits the memory usage to 1 kb / 1024 bytes.

A really good explanation on every memory parameter can be found in this article: https://www.alibabacloud.com/blog/docker-container-resource-management-cpu-ram-and-io-part-1_594573

Docker Memory limit with Docker UI/Desktop

If you have docker desktop or a docker UI available you could go into settings->resources and adjust the memory limits directly.

Docker Memory limit on WSL

You need to also take into account the environment in which you are running docker. For example if you are using WSL then you might also need to check the WSL memory limits. WSL already runs in a virtual machine. By default the WSL vm can use all the memory it has access to.

More information at https://docs.microsoft.com/en-us/windows/wsl/wsl-config#wsl-2-settings

How to check memory usage of Docker Containers?

If you run docker stats you should get information about every container, the cpu usage, memory usage, network usage and disk usage. For example see the screenshot below: