Start a container with memory limit and use tail to allocate memory
docker run -it --rm -m 32m --memory-swap 32m --name nginx nginx:1.20-alpine /bin/sh -c 'cat /dev/zero | head -c 8m | tail && echo Success'
docker run -it --rm -m 32m --memory-swap 32m --name nginx nginx:1.20-alpine /bin/sh -c 'cat /dev/zero | head -c 32m | tail && echo Success'