skip to Main Content

We’re running a docker container on AWS Beanstalk and on the Docker platform; ‘Docker running on 64bit Amazon Linux 2’
Have followed these guides to setup a swap-partition that is visible when running the command ‘swapon’.

Guides:

http://steinn.org/post/elasticbeanstalk-swap/

https://gist.github.com/steinnes/1f8a1b44fed4b136005f

When the docker instance is running and using all available memory, the process is immediately killed. No swap-space is being utilized.

Have also tried experimenting with various settings in the docker-compose.yml, but nothing seems to be working.

mem_limit: 16g (or omitting this setting)
mem_reservation: 8g (or omitting this setting)
memswap_limit: 48g or -1 
mem_swappiness: 0
privileged: true (tried this only to rule out that it had something to do with access rights)

I’m dead in the water on this one. Have any of you practical experience with creating swap partitions on Beanstalk Docker and actually verifying that the swap-space can be utilized by the container?

2

Answers


  1. Chosen as BEST ANSWER

    After lots of experimentation, I've found that it's possible to configure swap when using AWS's own 'Dockerrun.aws.json' instead of docker-compose.yml. AWS has the documentation for it here. The docs are targeted towards ECS but works with Beanstalk as well: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-swap.html

    The documentation adds the 'linuxParameters'-object to the Dockerrun.aws.json-file as shown below.

    'maxSwap': The total amount of swap memory (in MiB) a container can use.

    'swappiness': A swappiness value of 0 causes swapping to not occur unless required. A swappiness value of 100 causes pages to be swapped aggressively

    {
        "AWSEBDockerrunVersion": "1",
        "containerDefinitions": [
            {
                "linuxParameters": {
                    "maxSwap": 48000,
                    "swappiness": 0
                }
            }
        ]
    }
    

  2. I had a similar problem.

    When deploying the new build to EB, it fails to list docker containers with out of memory error. After this happened, re-deplying to the EB shown as success, but actually none of the changes were applied. (I added .platform/hooks/prebuild/setup_swap.sh similar to the URL in the question)

    It seemed like the process didn’t run because of out-of-memory, so that adding swap was not possible.

    I ended up manually adding swap to the instance with eb ssh, after that everything worked just fine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search