[FIXED] Docker Error 'failed to solve: process did not complete successfully'
The error ERROR: failed to solve: process "/bin/sh -c..." did not complete successfully: exit code: 1 is one of the most common and puzzling build failures encountered in Docker BuildKit (Buildx). This error message is merely a generic wrapper stating that a command executed by an instruction inside your Dockerfile returned a non-zero exit status.
Because BuildKit defaults to an interactive terminal UI that folds background stdout/stderr streams, the true root cause—such as a broken apt-get repository, an unhandled npm dependency conflict, out-of-memory limits, or architecture mismatches—remains hidden unless specifically queried.
Quick Diagnostics
RUN commands with && masking the failing stepdocker build --progress=plain --no-cache . to expose full verbose logsbullseye)apt-get update runs before install commands and verify package names for target architecture.dockerignore file excluding node_modules, .git, and local binary build artifactsStep-by-Step Solution
-
1
Step 1: Run the build in plain progress mode to expose raw logs
By default, BuildKit's TUI collapses multi-line outputs. Force plain-text output without cache to pinpoint the exact failure stream:
BASHdocker build --progress=plain --no-cache -t my-app:latest .Inspect the lines immediately preceding the final
failed to solveline. You will find the actual tool error, such asE: Unable to locate package,npm ERR! code ENOENT, or a missing compiler dependency. -
2
Step 2: Break down chained RUN statements into single directives
When a
Dockerfilebundles multiple operations into one line:DOCKERFILE# Hard to isolate when a middle step fails RUN apt-get update && apt-get install -y python3-pip curl && pip install -r requirements.txtTemporarily split each task into its own
RUNinstruction to isolate the exact failing binary:DOCKERFILERUN apt-get update RUN apt-get install -y python3-pip curl RUN pip install --no-cache-dir -r requirements.txtOnce you resolve the underlying problem, you can safely re-chain them to minimize final image layers.
-
3
Step 3: Prevent context bloat using a strict .dockerignore
If your build crashes with
exit code: 137(OOMKilled) orcontext canceled, Docker is likely attempting to ingest massive local directories into the build daemon. Place a.dockerignorefile in your repository root:TEXT.git .github node_modules dist build *.log .env .venvThis substantially speeds up build initiation and prevents incompatible host-compiled binaries from contaminating the container filesystem.
-
4
Step 4: Enforce target architecture and base image pinning
If developing on an Apple Silicon or ARM64 host while deploying to an x86_64 cloud instance, native binaries compiled inside
/bin/shmay fail silently. Explicitly define the target platform or pin the distribution:DOCKERFILE# Explicitly pin target platform for x86 architectures FROM --platform=linux/amd64 python:3.11-slim-bookworm WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python", "app.py"]
Frequently Asked Questions
Why does RUN apt-get install return exit code 100?
In Debian/Ubuntu environments, exit code 100 typically means the package list is stale (you must run apt-get update in the same RUN command) or an outdated Docker daemon is running on a host whose kernel syscalls conflict with modern glibc versions in Debian 12 Bookworm.
What is the advantage of docker buildx over traditional docker build?
Buildx is the next-generation Docker CLI plugin backed by BuildKit. It provides concurrent stage execution, multi-platform emulation, and advanced cache backends, requiring --progress=plain for uninterrupted terminal debugging.
Prevention Advice
Recommended security practices:
- Version pinning: Avoid floating tags like
latestin production Dockerfiles; pin exact version digests or stable tags (e.g.,node:20.18-alpine3.20). - Clean package caches within the same layer: Always pair repository updates and package installations with cache pruning (
apt-get update && apt-get install -y pkg && rm -rf /var/lib/apt/lists/*) to ensure deterministic builds. - Automated linting: Run
hadolintas part of your pre-commit hooks or CI/CD pipelines to catch bad practices before testing builds.