I'd like to use the composer cache from my host machine also in my DDEV containers to prevent unnecessary downloads and save time.
Asked
Active
Viewed 863 times
1 Answers
4
The solution is to create a new docker-compose.cache.yaml
in your .ddev
folder. The center word between the dots in the filename can be anything.
Content of the file should be like this (updated for ddev v1.1.1):
version: '3.6'
services:
web:
volumes:
- "$HOME/.composer/:/home/.composer/"
This maps $HOME/.composer
from your local machine to /home/.composer
in the DDEV container.
If you're working with Windows, $HOME/AppData/Local/Composer
should be the corresponding folder on your host machine.

rfay
- 9,963
- 1
- 47
- 89

Peter Kraume
- 3,577
- 2
- 21
- 39
-
2You can find the location of the composer cache on the host machine by using the command `composer config cache-dir` in the console. – Jigal van Hemert Aug 01 '18 at 07:49
-
It will be nice if we can figure this out as a standard technique for all, without any custom config. I'd recommend just simplifying the answer slightly, telling people to call the file "docker-compose.cache.yaml" (and mention that the center word is not so important). That just makes it so people have to think less, which is always good. – rfay Aug 01 '18 at 12:33
-
I've modified my answer slightly. – Peter Kraume Aug 01 '18 at 12:36
-
A great thing about this is that it not only uses the host's cache in the container, but it also means that every project will share the cache (assuming every project has the extra docker-compose.cache.yaml). – rfay Aug 01 '18 at 12:43
-
I added this as a general feature request at https://github.com/drud/ddev/issues/1027 – rfay Aug 01 '18 at 17:31
-
@rfay We can't assume that the host system has composer installed. Please, keep that in mind. – Jigal van Hemert Aug 02 '18 at 18:26
-
Thanks @JigalvanHemert - Yes, but this has value with or without host having it, because it's a way for projects to share composer cache. – rfay Aug 03 '18 at 19:42
-
As of v1.4.0 all projects share a composer cache directory (on a docker volume), so this workaround isn't needed any more. – rfay Nov 15 '18 at 14:11