This Docker build error occurs when a Dockerfile uses an ARG variable in the FROM instruction but the argument was not provided via --build-arg and has no default value. Fix it by providing a default value for the ARG or passing the build argument at build time.
The "no build argument" error for FROM in Docker indicates that your Dockerfile uses a variable in the FROM instruction (like `FROM ${BASE_IMAGE}`) but Docker cannot resolve what value to use for that variable. When you declare an ARG before FROM and use it in the FROM instruction to dynamically select the base image, Docker requires that variable to have a value at build time. This value can come from either: 1. A default value declared in the ARG instruction itself 2. A `--build-arg` flag passed to the `docker build` command If neither is provided, Docker cannot determine which base image to pull and the build fails immediately. This is by design - Docker's build check called "InvalidDefaultArgInFrom" enforces that a Dockerfile should be buildable without requiring `--build-arg` flags, meaning your ARG should have a sensible default value.
The recommended fix is to provide a sensible default value for your ARG so the build works without requiring --build-arg:
Before (broken):
ARG BASE_IMAGE
FROM ${BASE_IMAGE}After (fixed):
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}This way, if no --build-arg BASE_IMAGE=... is provided, Docker uses the default value ubuntu:22.04. You can still override it at build time:
docker build --build-arg BASE_IMAGE=alpine:3.18 -t myapp .If you intentionally want to require the build argument (no default), pass it with --build-arg:
docker build --build-arg BASE_IMAGE=python:3.11-slim -t myapp .For multiple build arguments:
docker build \
--build-arg BASE_IMAGE=node:20-alpine \
--build-arg APP_VERSION=1.0.0 \
-t myapp .Important: Do not add spaces around the equals sign. Use KEY=value, not KEY = value.
The ARG instruction must appear BEFORE the FROM instruction to be used in it:
Incorrect (ARG after FROM):
FROM ${BASE_IMAGE}
ARG BASE_IMAGE=ubuntu:22.04Correct (ARG before FROM):
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}Note: ARG is the ONLY instruction allowed before FROM. All other instructions (ENV, RUN, LABEL, etc.) must come after FROM.
Ensure the variable name in the ARG declaration exactly matches the usage in FROM:
Wrong (typo):
ARG BASE_IMG=ubuntu:22.04
FROM ${BASE_IMAGE}Correct:
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}Variable names are case-sensitive, so BASE_IMAGE and base_image are different variables.
Important: An ARG declared before FROM is ONLY available in the FROM instruction itself. After FROM, the ARG value is lost and must be re-declared:
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}
# This ARG re-declaration is needed to use the value after FROM
ARG BASE_IMAGE
RUN echo "Built from: ${BASE_IMAGE}"The re-declared ARG inherits the value passed via --build-arg but does NOT inherit the default value. If you need the default after FROM:
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}
ARG BASE_IMAGE=ubuntu:22.04
RUN echo "Built from: ${BASE_IMAGE}"If builds work locally but fail in CI/CD, ensure your pipeline passes the required build arguments.
GitHub Actions:
- name: Build Docker image
run: |
docker build \
--build-arg BASE_IMAGE=${{ vars.BASE_IMAGE }} \
-t myapp .GitLab CI:
build:
script:
- docker build --build-arg BASE_IMAGE=$BASE_IMAGE -t myapp .
variables:
BASE_IMAGE: "ubuntu:22.04"Docker Compose:
services:
app:
build:
context: .
args:
BASE_IMAGE: ubuntu:22.04Why Docker requires defaults for ARG in FROM:
Docker's build check "InvalidDefaultArgInFrom" enforces that Dockerfiles should be buildable without external configuration. This ensures:
- Reproducible builds across different environments
- Clearer documentation of which base images are supported
- Easier debugging when builds fail
Multi-stage builds and ARG scope:
In multi-stage builds, each FROM starts a new build stage. An ARG declared before the first FROM can only be used in FROM instructions, not within stages:
ARG BASE_VERSION=22.04
FROM ubuntu:${BASE_VERSION} AS builder
# ARG BASE_VERSION is NOT available here
FROM ubuntu:${BASE_VERSION} AS runner
# Still accessible in any FROM, but not inside stages
ARG BASE_VERSION
# Now it's available in this stageSecurity considerations:
Build arguments passed via --build-arg are visible in the image history. For sensitive values:
- Use Docker secrets instead of build arguments
- Consider multi-stage builds where secrets are only in the builder stage
- Use --secret flag with BuildKit for true secret handling
# Using BuildKit secrets (more secure)
docker build --secret id=mysecret,src=secret.txt -t myapp .Validating required build arguments:
If you truly want to make a build argument mandatory (fail fast with a clear error), add validation:
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-scratch}
ARG BASE_IMAGE
RUN test -n "${BASE_IMAGE}" || (echo "BASE_IMAGE is required" && exit 1)image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub