What does #(nop) mean in docker history?
NOP stands for "no operation".
Docker "runs a shell" for every layer. All the docker commands (or layers) in the Dockerfile except the RUN
command show up in the history as empty or commented out shell commands. The #
sign marks the start of the comment and anything after that will be skipped by the /bin/sh
. Similarly if you typing in the terminal:
user@machine $ echo hello world
hello world
user@machine $ #But none of these lines starting with # do anything
user@machine $ #echo hello world
The non-RUN
commands will not need to be interpreted by the shell, but instead are processed by docker internally.
The history (including the non-RUN
commands) can be used by the layer cache to skip processing in case the same command has been run previously.
FROM ruby:2.6-alpine
ENTRYPOINT ["sleep", "infinity"]
ENV A 1
$ docker build -t my-useless-image .
$ docher history --no-trunc my-useless-image
... CREATED BY ...
... /bin/sh -c #(nop) ENV A=1 ...
... /bin/sh -c echo test ...
... /bin/sh -c #(nop) ENTRYPOINT ["sleep" "infinity"] ...
...
For RUN
commands, it displays the shell command it executed, e.g.
/bin/sh -c echo test
For non-RUN
, /bin/sh -c #(nop)
followed by the Dockefile
command that was performed in that layer. /bin/sh -c #(nop)
doesn't really mean anything useful, and can be ignored. They made it look like a shell command, but it would fail if executed.