# Bitbucket Pipelines: Container 'Build' exceeded memory limit / Docker container exited with code 137

**Code:** `Container exceeded memory limit` · **Category:** CI/CD · **Seen on:** Bitbucket Pipelines

A Bitbucket Pipelines step used more memory than the step allows (4 GB by default, 1 GB for service containers) and was killed.

## Meaning

Each step gets a memory allotment shared by the build container and services (Docker service defaults to 1 GB). Raise the `size: 2x`, tune the Docker service memory in `definitions`, or reduce the tool's memory use.

## Common causes

- Build tools (webpack, Gradle, tsc) exceeding the limit
- Docker service container needing more than 1 GB
- Many parallel processes in one step
- Memory leak in tests
- Services (databases) consuming the step's memory

## Quick fix

1. Use `size: 2x` on the step (doubles memory)
2. Raise Docker memory in `definitions: services: docker: memory: 3072`
3. Limit workers and heap size

## Detailed fix by platform

### Bitbucket Pipelines

1. `size: 2x` costs double build minutes; set only on heavy steps

## Code examples

### Bigger step and Docker memory

```yaml
definitions:
  services:
    docker:
      memory: 3072
pipelines:
  default:
    - step:
        size: 2x
        services: [docker]
        script:
          - docker build -t app .
```

## How to diagnose

1. **Step** — Which step was killed?
2. **Memory** — Docker or build container?
3. **Workers** — Parallelism reduced?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cicd/bitbucket-pipelines-memory-exceeded)
