Series Pt. V — Optimizing Composer and Drush Docker images

In today’s story I narrate how I cut the size of my Docker Container for Drush from 224MB to 66MB.

Photo by Daniel von Appen on Unsplash
Drush (Red): 224MB; Composer (Yellow): 143MB
This is taking 70 megabytes !?!
Drush\Internal\Config\Yaml\Tag\TaggedValue
Drush\Internal\Config\Yaml\Escape
Class Drush\Internal\Config\Yaml\Parse
Class Drush\Internal\Config\Yaml\Yaml

Disable Composer Cache For Docker Builds

Adding the Composer global flag --no-cache prevents Composer from writing to a cache directory. In my case enable the--no-cache option results in an almost 50% percent size reduction while building my Drush container — from 124MB megabytes to 66.1MB .

# Inside Drush image build target.RUN composer global -vvv \
--no-cache \
install \
--no-dev
From ~124MB to 66.1MB
# Inside Drush image build target.RUN composer global -vvv \
--no-cache \
install \
--no-dev \
# added this option
--optimize-autoloader
Quick Smoke Test After Drush Install using drush — version
sudo make me beer

And that’s it!

I’ve completely achieved my goal of significantly reducing the size of my Composer and Drush containers. I did so by:

  1. Policing what I write into composer.json to make sure it’s the bare minimum.
  2. Adding the global Composer flag --no-cache to the composer install command inside my Dockerfile when installing any Composer dependencies such as Drush.

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store