[英]Can't install composer with docker on Google Cloud platform - Getting error Could not open input file: artisan
I am trying to build laravel project with docker on Google cloud platform.我正在尝试在 Google 云平台上使用 docker 构建 laravel 项目。 I am getting Could not open input file: artisan
error in Google logs.我收到Could not open input file: artisan
错误。 I have tried all solutions out there, unfortunately none of them is working:(我已经尝试了所有解决方案,不幸的是它们都不起作用:(
Here is my DockerFile这是我的 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.在本地使用 docker 命令构建它后,我收到此错误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.另外,我的根项目文件夹中有 artisan 文件。
I have exactly the same variables in Google Cloud platform variables as well.我在谷歌云平台变量中也有完全相同的变量。 My.env file is below. My.env 文件如下。
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?请告诉我我错过了什么?
You have to first COPY. .
你必须先COPY. .
COPY. .
and then run composer install
...然后运行composer install
...
I do not recommend to have CMD php artisan serve
as your image driver... just have another container like NGINX or Apache...我不建议让CMD php artisan serve
作为你的图像驱动程序......只要有另一个容器,如 NGINX 或 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...我也不建议在图像创建中安装和做任何事情......运行composer install
不是图像的一部分,如果是,你必须非常小心,就好像 composer 部分失败了,你没有图像用 php 做点什么……
Why do you have to COPY. .
为什么你必须COPY. .
COPY. .
before composer install
?在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因为你在正在构建的图像上什么都没有,你只有composer.json
所以composer install
可以工作,但是当它必须运行 composer 的安装后命令时,你什么都没有,这就是为什么你必须将所有东西都移动到图像中,然后安装
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.