Lesstep
Bitbucket Cloud · Pipelines · Checked October 29, 2026

Bitbucket Pipelines: "Container 'docker' exceeded memory limit."

The docker service, the Docker daemon behind your step's docker build, docker run and pipes, used more than its own memory: 1024 MB unless you set it. A bigger step size does not raise it by itself. Set the docker service's memory in bitbucket-pipelines.yml.

Why size: 2x did not help

Atlassian's article on this message (Bitbucket Pipeline build error "Container 'docker' exceeded memory limit") says the docker service keeps 1024 MB whatever the step size, until you allocate more. A larger step gives the extra memory to the build container, where your script runs, not to Docker.

The 1024 MB covers everything Docker does in the step: all containers started with docker run and the memory docker build needs (Run Docker commands in Bitbucket Pipelines).

Give the docker service more memory

definitions:
  services:
    docker:
      memory: 3072

pipelines:
  default:
    - step:
        services:
          - docker
        script:
          - docker build -t my-image .

memory is in megabytes. The docker service does not need an image: Pipelines provides it.

A step with a pipe

A pipe runs as a Docker container, and Pipelines adds a docker service to its step even when the step does not list one. That added service keeps 1024 MB: to give it your memory, list docker on the step yourself:

- step:
    services:
      - docker
    script:
      - pipe: atlassian/git-secrets-scan:3.1.0

How much you can give

The docker service can have the step's memory minus 1024 MB for the build container, minus the memory of the step's other services. With no other service, from Atlassian's article:

Step sizeStep memoryMost for docker
1x4096 MB3072 MB
2x8192 MB7168 MB
4x16384 MB15360 MB
8x32768 MB31744 MB
16x65536 MB63488 MB

4x and above are only for Standard and Premium plans, and a larger size uses that many times the build minutes of 1x (Step options).

Whatever Docker takes, your script loses. At 1x with memory: 3072 the build container has only 1024 MB left; if the script needs memory too, the step stops with "Container 'Build' exceeded memory limit." instead. Then use size: 2x and, for example, memory: 4096, which leaves the script 4096 MB.

Different memory for different steps

The memory of docker applies to every step that lists it. For one step that needs more, define another service of type docker, as Atlassian's documentation shows:

definitions:
  services:
    docker:
      memory: 1024
    docker-large:
      type: docker
      memory: 7168

pipelines:
  default:
    - step:
        name: Unit tests
        services: [docker]
        script:
          - docker build -t my-tests -f Dockerfile.test .
    - step:
        name: Image
        size: 2x
        services: [docker-large]
        script:
          - docker build -t my-image .

Keep the containers inside the limit

Bitbucket Pipelines in IntelliJ IDEA

Pipeline Inbox for Bitbucket Pipelines, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pipelines of all your Bitbucket Cloud repositories in an IDE tool window, with their steps, the failed step and the command it stopped at, and the step's log as Bitbucket writes it. The list, steps and logs are free; running, re-running and stopping pipelines are Pro (US$1.50 a month, with a 30-day trial).

Get it on JetBrains Marketplace

Atlassian, Bitbucket and Bitbucket Pipelines are trademarks of Atlassian; Docker is a trademark of Docker, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian, Docker or JetBrains.

More: Pipelines did not run after a push · "Container 'Build' exceeded memory limit." · "Exceeded build time limit of 120 minutes" · The cache is not used · "unexpected system error" · "command not found" · Submodules not cloned · "We couldn't clone the repository" · "No online runner available" · "No space left on device" · "Step exceeded processing limits" · The artifact is missing in the next step · The build passed before and fails now · Build setup takes too long · "You've run out of build minutes" · "Permission denied to update branch" · "You have reached your pull rate limit" (Docker Hub) · "There is an error in your bitbucket-pipelines.yml" · "This pipeline was paused" (deployments) · Bitbucket Pipelines plugins for IntelliJ IDEA, compared · 日本語