ReynierPM
ReynierPM

Reputation: 18660

How to execute a command from the host when it's on the $PATH?

I am installing the Laravel Installer as part of a Docker container using Composer. Laravel is installed globally meaning it goes to ~/.composer/vendor and then add an executable under ~/.composer/vendor/bin.

I am adding the directory ~/.composer/vendor/bin to the $PATH in a Dockerfile as follow:

ENV PATH="~/.composer/vendor/bin:${PATH}"

If I run the command docker exec -it php-fpm bash and from inside the container I run echo $PATH I got the following:

# 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

If I run the command laravel inside the container I got the following:

# 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.

So everything seems to be working fine. But if I run the following command (outside the container) meaning from the host:

$ docker exec -it php-fpm laravel

I got the following error:

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"

What I am missing here? Can the command laravel be run from within the host?

Upvotes: 0

Views: 294

Answers (1)

BMitch
BMitch

Reputation: 263577

The ~ is the problem here, it's not a valid path character for some shells exec doesn't process it as you'd hope, and it isn't expanded for you by the Dockerfile. Be explicit with your path with the following:

ENV PATH=/root/.composer/vendor/bin:${PATH}

Upvotes: 1

Related Questions