Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Dockerfile - Speed Up The Setting of Permissions

I am working on a few projects that have roughly 10,000 files, primarily because there is so much within the /vendor directory that gets pulled down using composer. This means that when I am setting the permissions as part of the docker build, it goes extremely slowly. Luckily, there are some things you can do to speed things up.

  1. The COPY docker command supports --chown which removes the need to do this as a separate RUN step.
COPY --chown=root:www-data source /var/www/my-site
  1. Compress your files into a single file. For PHP, you could possibly compress the vendor directory into a single PHAR file. I haven't tried this yet, but looks interesting. Javascript developers can use gulp to minify their files into one.

  2. If you are using composer to pull down PHP packages, make sure to use the --no-dev option so you don't pull down files you don't need.


Last updated: 8th August 2020
First published: 8th January 2019