gpt4 book ai didi

laravel - 在Docker容器中运行Laravel应用,但autoload.php文件不存在

转载 作者:行者123 更新时间:2023-12-02 19:51:19 26 4
gpt4 key购买 nike

我在docker中执行laravel应用时遇到问题,我的容器已成功启动,但是当我尝试访问我的应用时,出现此错误:

Warning: require(/var/www/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/public/index.php on line 24

Fatal error: require(): Failed opening required '/var/www/public/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/public/index.php on line 24

我不知道为什么,因为我在Dockerfile上运行了composer安装,因此我认为存在自动加载文件?

请找到我的 Dockerfile :
FROM php:7.2-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mariadb-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
libzip-dev \
git \
curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql tokenizer pcntl
RUN docker-php-ext-install gd zip

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY . /var/www

# Run composer install
RUN composer install
RUN composer dump-autoload

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

我的 docker-compose.yml :
version: '3'
services:

#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: bumapp
restart: unless-stopped
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
networks:
- app-network

#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
tty: true
ports:
- "80:80"
- "443:443"
networks:
- app-network

#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
volumes:
- dbdata:/var/lib/mysql
- ./docker/mysql/my.cnf:/etc/mysql/my.cnf
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: mustache
MYSQL_ROOT_PASSWORD: 888*
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- app-network
volumes:
dbdata:
driver: local
#Docker Networks
networks:
app-network:
driver: bridge

nginx / app.conf :
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}

也许您已经遇到了这个问题?

谢谢

最佳答案

我只是有同样的问题。
由于某些原因,在安装应用程序根卷以镜像本地环境(-./:/var/www)时,无法创建或写入vendor文件夹。
将卷“/ var / www / vendor”添加到您的应用程序。这将在容器中创建文件夹,并防止对该文件夹进行镜像。这使Laravel可以控制该文件夹并在其中创建所需的文件夹。
如果有人解释为什么镜像时无法创建或写入供应商文件夹,将不胜感激!

  #PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: bumapp
restart: unless-stopped
volumes:
- ./:/var/www
- /var/www/vendor
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
networks:
- app-network

关于laravel - 在Docker容器中运行Laravel应用,但autoload.php文件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60529973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com