docker inspect --format='{{.HostConfig.Memory}}' my_container
The .HostConfig.Memory field shows the memory limit in bytes. If no limit is set, it returns 0.
Memory limit sets the maximum memory a container can use (hard cap). Memory reservation reserves memory for the container but allows it to use more if available (soft guarantee).
services:
app:
image: myapp
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256MDocker Compose expects memory values with units like '512M' or '256M'. Adding 'B' or lowercase letters causes errors or misinterpretation.
If --memory-swap is unlimited, the container can use swap beyond the memory limit, so it may not be killed when exceeding the limit.
You must stop the container first, then restart it with the new memory limit flag. Afterwards, verify the setting and update configuration files if needed.
