ERROR: failed to build: failed to solve: file with no instructions means the
Dockerfile has text in it but not one instruction: every line is a comment or blank. In the
test the FROM line had been commented out. Remove the # from the
line you meant to keep, or add a FROM line.
With FROM alpine:latest uncommented, and the first comment left as it was, the
same build ended with exit code 0.
The error
docker build --progress=plain -t fix12-dkbuild-comments . 2>&1
#0 building with "desktop-linux" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 81B 0.0s done
#1 DONE 0.1s
Dockerfile:2
--------------------
1 | # Base image goes here
2 | >>> # FROM alpine:latest
3 |
--------------------
ERROR: failed to build: failed to solve: file with no instructions
exit=1
Why it happens
The file in the test had two lines, both starting with #, the second being
# FROM alpine:latest, and the
build stopped after reading it: only step #1 ran. The excerpt it printed puts
>>> on line 2, the last line with text, not on a line that is wrong in
itself.
Two more files were tried. Three line breaks and nothing else, 3 bytes, printed the same
file with no instructions, with the marker on line 3. A file of zero bytes printed
a different line, the Dockerfile cannot be empty. So in these runs the message
came from the two files that had characters but no instruction.
The fix
# Base image goes here
FROM alpine:latest
docker build --progress=plain -t fix12-dkbuild-commentsfix . 2>&1
...
#4 [1/1] FROM docker.io/library/alpine:latest@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6
#4 CACHED
...
#5 naming to docker.io/library/fix12-dkbuild-commentsfix:latest done
#5 unpacking to docker.io/library/fix12-dkbuild-commentsfix:latest 0.0s done
#5 DONE 0.2s
exit=0
The file above is the whole fixed Dockerfile: the hash in front of FROM is gone,
the comment above it stayed. A FROM line on its own was enough for this build to
finish.
How it was reproduced
A two-line Dockerfile of comments in a scratch folder, built on Docker Desktop 4.99.0 for
Windows with client and engine 29.9.3 and buildx v0.38.1; the fix used the cached
alpine:latest (image id 294b683cb724). Build commands ran in cmd,
started from PowerShell as cmd /c "... 2>&1", with the exit code
printed after each. Four builds: the comments file, the file of three line breaks, the
fixed file, and the zero-byte file, whose capture is copied, marked as a copy, from the
evidence of the other post linked below. The folders lab\comments,
lab\blank, lab\commentsfix and lab\empty and the
image tags fix12-dkbuild- plus each folder name are the test's own.
Frequently asked
- What does 'file with no instructions' mean in docker build?
- In the test it came from Dockerfiles with content but no instruction: one of only comments, where the FROM line had been commented out with a hash, and one of only line breaks.
- Can a Dockerfile start with a comment?
- Yes. The fixed file in the test started with a comment line and then FROM alpine:latest, and it built with exit code 0.
- What is the difference between 'file with no instructions' and 'the Dockerfile cannot be empty'?
- In the test a zero-byte file printed the Dockerfile cannot be empty, while files of only comments or only line breaks printed file with no instructions.
More decoded errors in the Fixes category. The zero-byte case has its own page, the Dockerfile cannot be empty, and for a Compose file of only comments, see empty compose file.