Docker Community Forums

Share and learn in the Docker community.

Limiting Physical/Swap memory at docker build-time

  • Issue type: docker API confusion
  • OS Version/build:

Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

  • App version: Docker version 19.03.5, build 633a0ea838

Trying to limit the physical and swap memory my docker containers can use by baking it in at build-time. Command being run to build is:

docker build -m 4m --memory-swap 7m image-name

I expect when the container is run that these limits will be placed by default
but when i inspect the running containers or do docker stats it never has any of the imposed limits described at build-time. Expecting in docker inspect:

“HostConfig” : {
“Memory”: 4000000
“MemorySwap”: 70000000
}

But these values show up as:

“HostConfig” : {
“Memory”: 0
“MemorySwap”: 0
}

When I do docker run -m 4m image-name it acts as expected and fails when it starts up due to Out Of Memory Exception. Is there something fundamental i’m missing about these docker build options about how they work? At least in accordance with the docker api: