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.
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.
definitions:
services:
docker:
memory: 3072
pipelines:
default:
- step:
size: 2x
services: [ docker ]
script: [ docker build -t app . ]Make the image build lighter
- Use multi-stage builds to drop heavy build deps from the final image.
- Cap memory in build commands run inside the image (heap limits).
- Pull a smaller base image where possible.
How to prevent it
- Allocate enough
memoryto the docker service for your largest build. - Use a
2xstep so build and docker both have headroom. - Keep image builds lean with multi-stage and small bases.