Composer Dockerfiles with different versions of PHP (mainly for our needs)
Move to the folder containing the desired Dockerfile.
Build the image
docker build -t <dockertag> .
Create a shell script called composer-php<version>.sh
with this content :
#!/bin/bash
docker run --rm --interactive --tty \
--env COMPOSER_HOME=/tmp/composer/config \
--env COMPOSER_CACHE_DIR=/tmp/composer/cache \
--workdir /app \
--volume $PWD:/app \
--volume ${COMPOSER_HOME:-$HOME/.config/composer}:/tmp/composer/config \
--volume ${COMPOSER_CACHE_DIR:-$HOME/.cache/composer}:/tmp/composer/cache \
--user $(id -u):$(id -g) \
<dockertag> composer "$@"
All images are available at : https://hub.docker.com/r/ihneo/composer
You can pull all images with the command :
docker pull ihneo/composer:<dockertag>
#!/bin/bash
docker run --rm --interactive --tty \
--env COMPOSER_HOME=/tmp/composer/config \
--env COMPOSER_CACHE_DIR=/tmp/composer/cache \
--workdir /app \
--volume $PWD:/app \
--volume ${COMPOSER_HOME:-$HOME/.config/composer}:/tmp/composer/config \
--volume ${COMPOSER_CACHE_DIR:-$HOME/.cache/composer}:/tmp/composer/cache \
--user $(id -u):$(id -g) \
ihneo/composer:<dockertag> composer "$@"
To use composer in version 1, command is composer
To use composer in version 2, command is composer2