ERROR: failed to build: failed to solve: dockerfile parse error on line 1: FROM requires either one or three arguments
came from a FROM line that was neither image nor
image AS name. In the test it was
FROM alpine latest, a space where the colon belongs. Write
FROM alpine:latest, or FROM alpine:latest AS name for a named stage.
The image and its tag are one argument joined by a colon. With the colon in place the same file built and ended with exit code 0.
The error
docker build --progress=plain -t fix12-dkbuild-twoargs . 2>&1
#0 building with "desktop-linux" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 67B done
#1 DONE 0.1s
Dockerfile:1
--------------------
1 | >>> FROM alpine latest
2 | CMD ["sh"]
3 |
--------------------
ERROR: failed to build: failed to solve: dockerfile parse error on line 1: FROM requires either one or three arguments
exit=1
Why it happens
FROM alpine latest has two words after FROM, and the build
stopped while reading the file: the output shows only step #1, the file with
>>> on line 1, and no image lookup. Four words,
FROM alpine:latest AS base extra, printed the identical line. One word,
FROM alpine:latest, built, and so did FROM alpine:latest AS base.
Three words without AS did not pass either. FROM alpine latest base
printed the same FROM requires either one or three arguments, after a build
check warning, FromAsCasing: 'latest' and 'FROM' keywords' casing do not match (line 1),
that read latest where AS belongs. So in these runs only
image and image AS name were accepted; the line number and the
>>> marker show where to look.
The fix
FROM alpine:latest
CMD ["sh"]
docker build --progress=plain -t fix12-dkbuild-twoargsfix . 2>&1
...
#4 [1/1] FROM docker.io/library/alpine:latest@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6
...
#5 naming to docker.io/library/fix12-dkbuild-twoargsfix:latest done
#5 unpacking to docker.io/library/fix12-dkbuild-twoargsfix:latest 0.0s done
#5 DONE 0.1s
exit=0
The file above is the whole fixed Dockerfile; the only change is the colon between the
image and the tag. To name the stage, add AS and a name as the second and third
words: the test file with FROM alpine:latest AS base also ended with exit code 0.
How it was reproduced
Five two-line Dockerfiles (two, four, one, three with AS and three without
words after FROM) on the cached alpine:latest (image id
294b683cb724), built on Docker Desktop 4.99.0 for Windows with client and engine 29.9.3 and
buildx v0.38.1. Each command ran in cmd, started from PowerShell as
cmd /c "... 2>&1", with the exit code printed after it. The folders
lab\twoargs, fourargs, twoargsfix,
threeargs and threenoas, the stage name base and the
image tags fix12-dkbuild- plus each folder name are the test's own.
Frequently asked
- What does 'FROM requires either one or three arguments' mean?
- The FROM line is not in a form the build accepted. In the test two words, four words, and three words without AS printed it; FROM alpine latest, with a space instead of a colon, was the first case.
- How do I write the tag in a Dockerfile FROM line?
- Join the image and the tag with a colon, as in FROM alpine:latest. That line built in the test, and FROM alpine:latest AS base did too.
- What happens with four words after FROM in a Dockerfile?
- Four words after FROM gave the same message in the test: FROM alpine:latest AS base extra failed with FROM requires either one or three arguments.
More decoded errors in the Fixes category. Another parse error, a misspelled instruction, is in dockerfile parse error: unknown instruction.