如何在$ PATH上执行主机的命令?
我正在使用Composer作为Docker容器的一部分安装Laravel Installer。 Laravel是全局安装的,意思是~/.composer/vendor
,然后在~/.composer/vendor/bin
下添加一个可执行文件。
我将~/.composer/vendor/bin
目录添加到~/.composer/vendor/bin
中的$PATH
中,如下所示:
ENV PATH="~/.composer/vendor/bin:${PATH}"
如果我运行命令docker exec -it php-fpm bash
并从容器内运行echo $PATH
我得到了以下内容:
# echo $PATH /opt/remi/php71/root/usr/bin:/opt/remi/php71/root/usr/sbin:~/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
如果我在容器中运行命令laravel
,我得到了以下内容:
# laravel Laravel Installer 1.3.3 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: help Displays help for a command list Lists commands new Create a new Laravel application.
所以一切似乎工作正常。 但是,如果我从主机运行以下命令(容器外部):
$ docker exec -it php-fpm laravel
我得到了以下错误:
rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"laravel\\\": executable file not found in $PATH\"\n"
我在这里错过了什么? 命令laravel
可以从主机内运行吗?
~
是这里的问题,对于某些shell来说这不是一个有效的path字符exec不会像你希望的那样处理它,而且Dockerfile也不会扩展它。 用以下的方式明确你的道路:
ENV PATH=/root/.composer/vendor/bin:${PATH}