'free' shows system memory statistics when execute inside of docker container with memory limits

When deriving a software scaling factor in a Docker-base CI environment, free always reports the memory statistics and limits of the host system.

Is it possible to report the limited amount of memory if a container was started with memory limitations?

How to reproduce:

free
docker run -it --rm --memory=4G alpine:latest

Inside Alpine Linux:

free

In some scenarios it's helpful to not just derive a software scaling factor (e.g., make -j$(nproc)) from number of available CPU cores, but also from available memory. E.g., compiling using multiple parallel GCC instances is uncritical, but compiling with G++ consumes way more memory.


A similar problem was reported to nproc, which is currently discussed here: coreutils/coreutils#108 and here: https://lists.gnu.org/archive/html/bug-gnulib/2025-08/msg00000.html