Speed up dockerization

I am deploying Julia code using docker. In order to speed up the startup of the container I build a package using PackageCompiler.jl.

However this is painfully slow, as it rebuilds everything even if I change one line in the final main entrypoint. Are there any best practices to speed this up? How could I build a sysimage with just the packages and do not precompile my application code? Do I just make a sysimage in a builder stage and copy it over into the the final output stage of the image, together with the main application source code?

I went with a persistent build cache that stores the precompiled package images so that the dependencies don’t need to be recompiled every time. I followed this post.

Is the source code of the packages still in the image? I cannot have that for some private packages.