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?

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.