0

I'm having some issues with running the laravel command on my docker container. I use the php docker image and use the copy command for getting composer from the composer image. After that I've added composer to my $PATH variable and run the composer global require laravel/installer command.

After building the docker compose file and running it I open up the command line for my php image. In here I try to run the "laravel" command but get the following error: /bin/sh: laravel:not found.

Looking in the $HOME/.config/composer/vendor folder I see laravel here, so I think the installation is correct.

I might be completely wrong here or have made a dumb rookie mistake, so any help is greatly appreciated

Below here is my dockerfile:

FROM php:8.0.14-apache
RUN docker-php-ext-install pdo pdo_mysql

#apache
RUN a2enmod rewrite

#composer

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer



#add composer to path

ENV PATH="$PATH:$HOME/usr/local/bin/composer"

RUN export PATH="$PATH:$HOME/.composer/vendor/bin"

#update

RUN apt-get update

RUN apt-get -y install nano

#add nodejs

RUN apt-get -y install nodejs npm

COPY . /var/www/html/

RUN npm install

#install laravel

RUN composer global require laravel/installer
1
  • 1
    Could you share what error you see ? Could you check the log file to see what's happening ? Commented May 18, 2022 at 21:51

2 Answers 2

2

You copy composer to /usr/local/bin/composer, but you add $HOME/usr/local/bin/composer to the path.

Also, RUN export ... doesn't do anything, because each RUN statement is run in a separate shell. So when the RUN command is done, the shell exits and the exported variable is lost.

Try this

FROM php:8.0.14-apache
RUN docker-php-ext-install pdo pdo_mysql

#apache
RUN a2enmod rewrite

#composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

#add composer to path
ENV PATH="$PATH:/usr/local/bin/composer"

#update
RUN apt-get update
RUN apt-get -y install nano

#add nodejs
RUN apt-get -y install nodejs npm

COPY . /var/www/html/

RUN npm install

#install laravel
RUN composer global require laravel/installer
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for letting me know about the fact that the run statement is runs in a separate shell. It seems like I needed to add the changed current directory that the command composer global about returns and add /vendor/bin behind it. Don't know if its bad practise to add a root path to the $PATH variable, but it works for now.
1

I've added the "changed path" from the command composer global about to my ENV path and added /vendor/bin. I'm not sure if its bad practise to add something from the root folder to the $PATH variable.

So the complete line looks like this:

ENV PATH="$PATH:/root/.config/composer/vendor/bin"

By adding this line i'm able to run the laravel command

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.