Test in Docker container fails with error 137 indicating a probable memory leak

name: Docker Image CI

on: [push]

    runs-on: ubuntu-latest

      - uses: actions/checkout@v1
      - name: Build the docker-compose stack
        run: docker-compose -f docker-compose.yaml up -d
      - name: Check running containers
        run: docker ps -a
      - name: Check logs
        run: docker logs web_container
      - name: Run jest test suite
        run: docker exec -w /home/node/app web_container npm run test
      - name: Run cypress test suite
        run: docker exec -w /home/node/app web_container npm run test:e2e

This command is supposed to run jest

docker exec -w /home/node/app web_container npm run test

and this is supposed to run cypress

docker exec -w /home/node/app web_container npm run test

My repository works fine in local computer but fails in github actions.

Link to my repository: https://github.com/pvgdev/nextjs-template


Error 137 in Docker denotes that the container was killed by ‘OOM killer’ (Out of Memory). This happens when there isn’t enough memory in the container for running the process.
The 2 main out-of-memory reasons:

  1. Docker container has run out of memory
    By default, Docker containers use the available memory in the host machine. To prevent a single container from abusing the host resources, there may be some memory limits set for per container on the virtual machines of GitHub-hosted runners.
    It is important not to allow a running container to consume too much of the host machine’s memory.

  2. Docker host has no free memory
    Each virtual machine of GitHub-hosted runner has the same hardware resources available.

    • 2-core CPU
    • 7 GB of RAM memory
    • 14 GB of SSD disk space

    The memory limit that can be allotted to the Docker containers is limited by the total available memory in the host machine which hosts them.
    Many often, when usage and traffic increases, the available free memory may be insufficient for all the containers. As a result, containers may crash.

To resolve error 137 in Docker, you can try with the following steps:

  1. Optimize the services
    Unoptimized applications could take up more than optimal memory. So, the first step is to monitor the application running in the container and to optimize the service. This can be done by editing the configuration file or recompiling the service.

  2. Mount config files from outside
    It is always advisable to mount the config files of services from outside the Docker container. This will allow to edit them easily without recompiling the Docker image.

To view more details about container’s resource constraints, you can see “Runtime options with Memory, CPUs, and GPUs”.