Installing PHP Composer with Docker

‹ What is slf4j? | Running LaTeX inside Docker ›

PHP 5.6 FPM

Installing

CONTAINER_INSTALL_DIR=/composer
DOCKER_IMAGE=php:5.6-fpm-alpine
cd /path/to/directory/where/you/want/composer
docker run -i -t --rm -v `pwd`:"$CONTAINER_INSTALL_DIR" \
  "$DOCKER_IMAGE" php \
  -r "copy('https://getcomposer.org/installer', '$CONTAINER_INSTALL_DIR/composer-setup.php');"
docker run -i -t --rm -v `pwd`:"$CONTAINER_INSTALL_DIR" \
  "$DOCKER_IMAGE" php \
  -r "if (hash_file('SHA384', '$CONTAINER_INSTALL_DIR/composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('$CONTAINER_INSTALL_DIR/composer-setup.php'); } echo PHP_EOL;"
docker run -i -t --rm -v `pwd`:"$CONTAINER_INSTALL_DIR" \
  "$DOCKER_IMAGE" sh -c "cd $CONTAINER_INSTALL_DIR; php composer-setup.php"
rm -f composer-setup.php

Running

CONTAINER_INSTALL_DIR=/composer
DOCKER_IMAGE=php:5.6-fpm-alpine
docker run -i -t --rm -v `pwd`:"$CONTAINER_INSTALL_DIR" \
  "$DOCKER_IMAGE" "$CONTAINER_INSTALL_DIR"/composer.phar

Subscribe to All Posts - Wesley Tanaka