I am trying to build laravel project with docker on Google cloud platform. I am getting Could not open input file: artisan
error in Google logs. I have tried all solutions out there, unfortunately none of them is working :(
Here is my DockerFile
FROM php:8.1
ENV PORT 8080
RUN apt update
RUN apt install wget
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y zip
RUN apt-get install -y unzip
RUN apt-get install -y curl
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --2
WORKDIR /app
COPY composer.json .
RUN composer install
RUN apt-get update && apt-get install -y \
software-properties-common \
npm
RUN npm install npm@latest -g && \
npm install n -g && \
n latest
COPY . .
CMD php artisan serve --host=0.0.0.0 --port 8080
After building it using docker command locally, I get this error Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
in the terminal.
Also, I have the artisan file in my root project folder.
I have exactly the same variables in Google Cloud platform variables as well. My .env file is below.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64: ly4U3QbWcULnj0A31g41q7Yim/L0W5olgwPbsuD1/A=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8080
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=test
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=root
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Please tell me what am I missing?
CodePudding user response:
You have to first COPY . .
and then run composer install
...
I do not recommend to have CMD php artisan serve
as your image driver... just have another container like NGINX or Apache...
I also do not recommend installing and doing stuff in the image creation... running composer install
is not part of an image, and if it is, you have to be very careful, as if the composer part fails, you have no image to do something with php...
Why do you have to COPY . .
before composer install
? Because you have nothing on the image being built, you only have composer.json
so composer install
works, but when it has to run composer's post install commands, you have nothing else, that is why you have to move EVERYTHING into the image, then install