3

I'm new to Docker and got my PHP environment set up with this as my Dockerfile:

FROM php:7.0-apache
COPY src/ /var/www/html/

Now I want to use PHP code I found on github and it says to install it I simply have to do:

composer require league/oauth2-client

Upon getting a shell into my docker container composer isn't even installed. How do I add composer into the Dockerfile and then execute the composer commands I need?

Tom Freezers
  • 227
  • 3
  • 9

2 Answers2

1

I was able to solve this by adding this to the Dockerfile

RUN php -r "copy('https://getcomposer.org/installer', 'composer- setup.php');"
RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN php -r "unlink('composer-setup.php');"
RUN composer require league/oauth2-client
Tom Freezers
  • 227
  • 3
  • 9
0

Upon getting a shell into my docker container

That would be at runtime (docker run)

Instead, create a new Dockerfile, which starts with FROM myimage (the php image you created), and add / copy what is missing.

See for instance "Get composer (php dependency manager) to run on a docker image build" as a possible approach.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250