Skip to content
Latchkey

Bitbucket Docker Service Memory Too Low - Image Build OOM

The docker service runs the daemon for your image builds and draws from the step memory budget. A heavy docker build can exceed the docker service’s allocation and get OOM-killed.

What this error means

A docker build fails partway with the daemon dying or the step OOMing, while the same build works locally. Raising the docker service memory (and/or the step size) lets it complete.

Bitbucket log
failed to solve: process "/bin/sh -c npm run build" did not
complete successfully: exit code: 137
Cannot connect to the Docker daemon ... (daemon was killed)

Common causes

Docker service has too little memory

The docker service’s default memory is modest. A multi-stage build, a large base image, or a memory-heavy build command inside the image can exceed it and kill the daemon.

Step budget split between build and docker

The build container and the docker service share the step total. A small step size leaves little for the docker daemon once the build container takes its share.

How to fix it

Increase docker service memory

Raise the docker service’s memory in definitions, sizing the step to fit.

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

Make the image build lighter

  1. Use multi-stage builds to drop heavy build deps from the final image.
  2. Cap memory in build commands run inside the image (heap limits).
  3. Pull a smaller base image where possible.

How to prevent it

  • Allocate enough memory to the docker service for your largest build.
  • Use a 2x step so build and docker both have headroom.
  • Keep image builds lean with multi-stage and small bases.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →