Home > Software engineering >  Unable to run laravel command on docker with composer
Unable to run laravel command on docker with composer

Time:05-20

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

CodePudding user response:

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

CodePudding user response:

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

  • Related