[英]How to install Composer with docker exec
I'm trying to install composer on docker container. 我正在尝试在docker容器上安装composer。 I have a container laravel55
and I'm gonna to install composer insite it. 我有一个容器laravel55
,我要在现场安装composer。
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: Aftar安装,我正在尝试使用composer
但它不起作用:
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! 似乎尚未安装Composer! How can I install composer on a docker container? 如何在Docker容器上安装composer?
Well with your command you're actually installing composer.phar locally on your host, you just execute the curl command inside the container. 使用命令,您实际上是在主机上本地安装composer.phar,只需在容器内执行curl命令即可。 The part behind the pipe symbol |
管道符号后面的部分|
is not executed in your docker container but on your host. 不是在您的docker容器中执行,而是在您的主机上执行。 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. 在第二个命令中,将工作目录切换到/var/www/html
,您显然希望在其中找到composer.phar
但在第一个命令中则没有。
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"
You could use official composer image from dockerhub and mount on it a volume from your app container 您可以使用dockerhub中的官方composer映像并将其从应用容器中挂载到一个卷上
ie 即
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.