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 .
Docker rmi To remove the image, you first need to list all the images to get the Image IDs, Image name and other details. By running simple command docker images -a or docker images . After that you make sure which image want to remove, to do that executing this simple command docker rmi <your-image-id> .
If you are fine with keeping a single image, you can use docker image prune -f , which will remove all images but the ones associated with a container, so if you run this command while the container is running, it will remove the rest of the images.
A multistage build allows you to use multiple images to build a final product. In a multistage build, you have a single Dockerfile, but can define multiple images inside it to help build the final image.
This Docker behaviour is here on purpose, it leaves this image for caching purposes - for when a build will be triggered next time.
For now there is no option to delete it while building.
The only option to get rid of this image is to delete it manually. One of the many possibilities:
$ docker image prune
Executed afterwards. This command removes all dangling images. Specifically, it removes all images not referenced by any local container, which includes the <none>
image you mentioned.
ticket ref
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With