Q:

How to delete image from previous stage on Docker multi-stage build

Here is my Dockerfile
FROM microsoft/aspnetcore-build as build-stage
ARG source=.
WORKDIR /app
COPY $source/sample-api.csproj .
RUN dotnet restore
COPY $source .
RUN dotnet publish -o /publish

FROM microsoft/aspnetcore
WORKDIR /sample-api
COPY --from=build-stage /publish .
EXPOSE 3000
ENTRYPOINT dotnet sample-api.dll

That will create 2 images
REPOSITORY     TAG          IMAGE ID
sample-api     latest       
<none>         <none>

Is it possible to delete the first stage image <none> from the second stage? It is not needed anymore after the COPY on the second stage is executed COPY --from=build-stage /publish .

A:

This Docker behavior is there on purpose, it leaves this image for cache'ing purpose - when a build will be triggered for the next time. 
For now there is no option to delete it while building.
The only option to get rid of this image is deleting it manually. One of many possibilities:
$ docker image prune

Executed afterwards. This command removes all dangling images - that includes the one you mention.
ticket ref

