Dockerfile not executing second stage

  docker, docker-multi-stage-build, dockerfile, linux, ubuntu

I’m getting some weird behavior from Docker and I can’t find it mentioned anywhere. It is skipping stages seemingly at random, even with multi-stage Dockerfiles that I’ve simply copy-pasted from forums around the net.

My dockerfile is:

FROM alpine as base
RUN echo "1"

FROM base as mid
RUN echo "2"

FROM base as final
RUN echo "3"


docker build -t test . --no-cache
[+] Building 2.0s (7/7) FINISHED
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 34B                                                                                   0.0s
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 143B                                                                               0.0s
 => [internal] load metadata for                                                   1.3s
 => CACHED [base 1/2] FROM[email protected]:...  0.0s
 => [base 2/2] RUN echo "1"                                                                                        0.3s
 => [final 1/1] RUN echo "3"                                                                                       0.4s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:...                      0.0s
 => => naming to                                                                 0.0s

What causes this?

Source: Docker Questions