Docker provides ways to control how much memory, or CPU a container can use, setting runtime configuration flags of the docker run command.
You could use --memory-swap which is a modifier flag along with the docker run command.Using swap allows the container to write excess memory requirements to disk when the container has exhausted all the RAM that is available to it. There is a performance penalty for applications that swap memory to disk often.
For a further understanding refer: https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details