Docker Build Command Output Not Showing: Fixes and Solutions
When building Docker images, you may notice that command output from RUN
instructions isn't displayed, making debugging difficult. This article explains why this happens and provides several solutions to show the command output during builds.
Problem: No Output from RUN Commands
By default, Docker BuildKit (the modern build system) shows minimal output:
FROM node:12.18.0
RUN echo "hello world"
RUN psql --version
Instead of seeing the expected "hello world" and psql version output, you see:
=> [7/18] RUN echo "hello world" 0.9s
Root Cause: BuildKit's Default Behavior
Docker's BuildKit engine (default since Docker 18.09) uses a condensed output format that doesn't show command output by default. This differs from the older Docker build engine which was more verbose.
Solution 1: Use Plain Progress Output (Recommended)
The most straightforward solution is to use the --progress=plain
flag:
docker build --progress=plain .
For Docker Compose:
docker compose build --progress=plain <container_name>
This shows the full output of all commands during the build process.
Solution 2: Set Environment Variable for Permanent Change
To avoid specifying the flag every time, set the environment variable:
export BUILDKIT_PROGRESS=plain
Now all subsequent docker build
commands will show full command output.
Solution 3: Disable Caching When Debugging
If your commands have been cached from previous builds, use --no-cache
to force re-execution:
docker build --progress=plain --no-cache .
WARNING
Using --no-cache
significantly increases build time as it rebuilds all layers from scratch.
Solution 4: Revert to Legacy Build Engine
If you prefer the old behavior, you can disable BuildKit entirely:
DOCKER_BUILDKIT=0 docker build .
Or set it permanently:
export DOCKER_BUILDKIT=0
INFO
The legacy build engine may be deprecated in future Docker versions, so this is not a long-term solution.
Advanced: Force Command Execution with Cache Busting
If you need to see output from a specific command without rebuilding everything, you can add a cache-busting technique:
RUN your_command && echo "cache-bust-$(date +%s)"
Change the cache-busting string each time to force Docker to rerun the command.
Common Pitfall: Windows Line Endings
If you see errors like /bin/sh: 1: /install.sh: not found
, you might have Windows line endings (CRLF) in your scripts. Convert them to Unix line endings (LF) using your editor.
TIP
In VS Code, click the "CRLF" button in the bottom right corner and select "LF" to convert line endings.
Summary
Method | Command | Use Case |
---|---|---|
Plain progress | docker build --progress=plain . | Temporary debugging |
Environment variable | export BUILDKIT_PROGRESS=plain | Permanent solution |
No cache | docker build --progress=plain --no-cache . | Force all commands to rerun |
Disable BuildKit | DOCKER_BUILDKIT=0 docker build . | Legacy behavior |
The recommended approach for most cases is using --progress=plain
when you need to debug builds, or setting BUILDKIT_PROGRESS=plain
as an environment variable for consistent verbose output.