Could use some feedback on this multistage dockerfile (1st elixir/phoenix deployment)

Yes, you made a very good point. My dockerfile needs more tweaking. Will do it soon.

Hi @otijhuis, I took your idea and made some updates to my dockerfile. Now it works pretty well.

A fresh build takes about 2 minutes, because I have some expensive dependencies. A repeated build with a single line of code changed takes around 5 seconds, which is the same as yours as I follow the same strategy with you.

I split it into smaller stages because I want to make it easy to fit into another project without any assets. Eventually I will update my library dockerize later.

Currently, the building workflow goes like this:

This picture shows what stage will be rebuilt based on the location of the change (green texts on the top left).

4 Likes

Looks good!

You might be able to use the same multistage dockerfile for both elixir and phoenix projects by using the --target option of docker build. One final image stage for phoenix, one for elixir only. When using buildkit it won’t execute what it won’t need and you could pick between docker build --target elixir . and docker build --target phoenix .. You might have to tweak a bit but I suspect it’s possible. I could be wrong though :slight_smile:

Yes, I believe it’s possible and that would be interesting. But I’ll keep it as it is now because it will be used in a hex package. In my case of a library generating dockerfiles for other projects, I prefer to keep them as two templates sharing common small stages. This is only from the perspective from a library though.