News for hackers. Stuff that matters.
Re:Crafting container images without Dockerfiles by kevincox on Monday February 06, 2023 @01:04PM (#34681464)
It depends. There is some implicit "bloat" because setting up 100 layers and accessing files through them isn't free (but caching works quite well). However the biggest problem with layers is that you can never delete data. So doing something like `RUN apt-get install foo` `RUN foo generate-things` `RUN apt-get uninstall foo` will effectively still have `foo` in the image.

It definitely depends on the use case. In many cases `RUN foo`, `RUN bar`, `RUN baz` is fine. But if you are every creating temporary data in an image the layer system will keep that around. This is why you often see things like `RUN apt-get update && apt-get install foo && rm -r /var/lib/apt`. You squeeze it into a single layer so that the deletion of the temp files actually avoids image bloat.

Re:Crafting container images without Dockerfiles by throwaway290 on Monday February 06, 2023 @01:40PM (#34682000)
It is possible with build stages and copy from, but yeah not super trivial.
Re:Crafting container images without Dockerfiles by kevincox on Monday February 06, 2023 @01:45PM (#34682090)
Exactly. You need to remember to do it and restructure your build at least slightly to do so. It isn't hard but non-default and annoying.
Re:Crafting container images without Dockerfiles by mcronce on Monday February 06, 2023 @03:58PM (#34684231)
Definitely not trivial, but staged builds are my go-to solution. Depending on the specifics of the tech you're including it can be a lot easier than figuring out how to clean up every little build artifact within a layer - just add a second FROM line and copy precisely the pieces you need in the final image, and nothing else.

I also think it makes the build stage a lot easier to follow for people who aren't as familiar with Dockerfiles and all the quirks that come with optimizing a final image.