0

I'm trying to install composer on docker container. I have a container laravel55 and I'm gonna to install composer insite it.

docker exec laravel55 curl --silent --show-error 
https://getcomposer.org/installer | php

#result
Composer (version 1.6.5) successfully installed to: /root/docker- 
images/docker-php7-apache2/composer.phar
Use it: php composer.phar

Aftar installation, I'm trying to using composer but it doesn't work:

 docker exec -w /var/www/html laravel55 php composer.phar install

#result
Could not open input file: composer.phar

It seems that Composer had not installed! How can I install composer on a docker container?

1

2 Answers 2

4

Well with your command you're actually installing composer.phar locally on your host, you just execute the curl command inside the container. The part behind the pipe symbol | is not executed in your docker container but on your host. In your second command you switch your working directory to /var/www/html where you apparently expect the composer.phar but not in the first command.

So to make the whole command run in the container, you can try the following:

docker-compose exec -w /var/www/html laravel55 \
    sh -c "curl --silent --show-error https://getcomposer.org/installer | php"
Sign up to request clarification or add additional context in comments.

1 Comment

It's worked, thank you. I had written docker-compose instead of docker by mistake so I updated my question.
1

You could use official composer image from dockerhub and mount on it a volume from your app container

i.e

docker run -td --name my_app --volume /var/www myprivateregistry/myapp

docker run --rm --interactive --volumes-from my_app --volume /tmp:/tmp --workdir /var/www  composer install

3 Comments

I'm confused. Does it run composer install in /var/www ?
/var/www is a volume from your container app
As per documentation, this approach is not the best choice since you may need to run scripts at the end of the composer install or you may need some extensions that the built in php in the image does not provice, resulting in errors. The best approach would be to install composer inside your docker instance as the documentation suggests

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.