How speeding up composer install led to reducing PHP docker image build time by up to 5 times

Have you ever profiled how long it takes for your PHP or PHP-FPM docker image to build? Probably, you have noticed that the composer install step accounts for the bulk of the image build time.

In this post, I will reveal one of the effective ways that helped us reduce the docker build time by a factor of 5. We decreased it from 5 minutes to 1.

The changes are done in the base image so that this plugin’s goodness will be propagated to all projects using that base image.

Image for post

Adding hirak/prestissimo to our base PHP-FPM image

288s -> 26s

In my case the composer update used to take around 10 minutes to finish, now after utilising this package, it turned into 1 min and less, which is blazingly faster for me.

Image for post

Before the plugin, it took 5 mins for the PHP Docker image to build

Image for post

After the plugin was added it took 1 minute for the same PHP Docker image to build

Conclusion