Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

How to modify max memory while running docker run? #37

Closed
msjoshi opened this issue Jun 11, 2017 · 2 comments
Closed

How to modify max memory while running docker run? #37

msjoshi opened this issue Jun 11, 2017 · 2 comments

Comments

@msjoshi
Copy link

msjoshi commented Jun 11, 2017

I'm using the following command to run a lambda function as described in the docs.
docker run -v "$PWD":/var/task lambci/lambda index.myHandler '{"some": "event"}'

By, default it uses max memory of 1536MB. I tried modifying the max memory by using the following.
docker run -v "$PWD":/var/task lambci/lambda index.myHandler '{"some": "event"}' ['-m', '512M']

The output still shows max memory of 1536MB. I appreciate, if anyone can help me on changing max memory.

@homingli
Copy link

You can use -e for setting environment variables, as referenced in Docker documentation:
https://docs.docker.com/engine/reference/run/#env-environment-variables

Example:

$ cat lambda_function.py
def lambda_handler(event, context):
    print(context.memory_limit_in_mb)
    return "It works!"

Without env var:

$ docker run --rm -v "$PWD":/var/task lambci/lambda:python3.6
START RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe Version: $LATEST
1536
END RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe
REPORT RequestId: 11038b32-74fc-40fb-9b41-120aa7065dfe Duration: 10 ms Billed Duration: 110.00000000000001 ms Memory Size: 1536 MB Max Memory Used: 18 MB
"It works!"

With env var:

$ docker run --rm -v "$PWD":/var/task -e "AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128"   lambci/lambda:python3.6
START RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4 Version: $LATEST
128
END RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4
REPORT RequestId: ef3b26e2-6780-4564-a0b9-15b45b1293a4 Duration: 20 ms Billed Duration: 120.0 ms Memory Size: 128 MB Max Memory Used: 18 MB
"It works!"

However, I'm not sure what the behavior here is when your function exceeds the memory limit set by the env var.

@mhart
Copy link
Member

mhart commented Jul 1, 2017

Thanks @homingli – you're absolutely correct. To actually get docker to restrict the memory to try to simulate what would happen, you can use the -m flag with the docker run command: https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources

@mhart mhart closed this as completed Aug 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants