The original post: /r/php by /u/gaufde on 2024-12-23 18:08:38.

I’m playing around with running Composer in a container rather than having it installed directly on my development machine. This seems to be a pretty popular thing to do, but I’m having trouble getting it working without some sort of undesirable behavior. I’d like to have a discussion about methodologies, so I’ll describe what I’ve done to kick things off.

Here is the method I am trying. First, I have created a Containerfile so that I have some extra control over the image that will run Composer:

FROM php:8.2-fpm-alpine

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions \
    gd \
    zip \
    @composer-2.8.4

Then, after I’ve built the above image, I set up an alias in my shell to make it easy to run:

alias composer='podman run --rm \
--volume "$PWD:/app" \
--volume "${COMPOSER_HOME:-$HOME/.composer}:/var/www/html/.composer" \
--user $(id -u):$(id -g) \
localhost/local/composer composer'

Note: because I am on MacOS, Podman is running in a linux VM using the default podman machine mechanism which runs Fedora Core OS.

This works pretty well; however .composer directories keep getting created and left in my working directory after I run a composer command. I’m assuming that I don’t have Composer’s caching mechanisms configured correctly, but I have yet to figure that out.

So, my question is, how do other people set this up for themselves on their local development machines? Also, why do you do it using the method you have chosen?