'What does #(nop) mean in docker history?

What does the #(nop) prefix mean when listing docker history?

$ docker history swarm
IMAGE               CREATED             CREATED BY   
c54bba046158        9 days ago          /bin/sh -c #(nop) CMD ["--help"]


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1