You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署的Laravel应用加载缓慢问题排查求助

我正在开发一款测验应用,将Laravel应用部署到Docker后,发现应用加载速度极慢——一个包含5个输入框的表单页面加载耗时约7-8秒。
表单加载耗时

我知道这个等待时间过长,因为几周前我部署的另一款Laravel Docker应用运行速度很快,但现在无法再使用它。我怀疑问题可能出在.yml文件和Dockerfile中,但不清楚具体的配置问题。

由于我使用的是Windows 10 Home系统,无法在Docker界面中禁用Use the WSL 2 based engine (Windows Home can only run the WSL 2 backend)选项。

docker-compose.yml
version: '3'
services:
  mariadb:
      image: mariadb
      restart: always
      ports:
        - 3375:3306
      environment:
        TZ: "Europe/Bucharest"
        MARIADB_ALLOW_EMPTY_PASSWORD: "no"
        MARIADB_ROOT_PASSWORD: "user@pass"
        MARIADB_ROOT_HOST: "%"
        MARIADB_USER: 'user'
        MARIADB_PASSWORD: 'pass'
        MARIADB_DATABASE: 'db'
      networks:
        - sail
      volumes:
      - ./docker-config/server_bd:/var/lib/mysql

  app:
    build: ./docker-config
    container_name: app
    ports:
        - 8000:80        
        - 4430:443
    volumes:
        - "./:/var/www/html"
    tty: true
    networks:
       - sail
    links:
      - mariadb
    depends_on:
      - mariadb

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    networks:
      - sail
    links:
      - "mariadb:db"
    depends_on:
      - mariadb
    environment:
      UPLOAD_LIMIT: 1024M
    ports:
      - 3971:80    
  
networks:
    sail:
      driver: bridge

volumes:
  data:
    driver: local
Dockerfile
FROM ubuntu:20.04

EXPOSE 80

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update -y
RUN apt-get upgrade -y

RUN apt install -y lsb-release
RUN apt-get clean all

RUN apt-get install ca-certificates apt-transport-https -y
RUN apt-get install software-properties-common -y

# Apache Server
RUN apt-get -y install apache2
RUN a2enmod rewrite
RUN service apache2 restart

# SETUP SSL
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
    a2enmod rewrite &&\
    a2enmod ssl

COPY cert/certificate.crt /etc/ssl/certificate.crt
COPY cert/private.key /etc/ssl/private.key
COPY cert/ca_bundle.crt /etc/ssl/ca_bundle.crt

COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
RUN service apache2 restart

RUN apt-get install -y wget

RUN apt-get install nano

RUN apt-get update -y

RUN apt-get install -y apt-transport-https

# PHP8
RUN add-apt-repository ppa:ondrej/php
RUN apt-get install -y php8.1
RUN apt-get install -y php8.1-fpm
RUN apt-get install -y libapache2-mod-php
RUN apt-get install -y libapache2-mod-fcgid
RUN apt-get install -y curl
RUN apt-get install -y php-curl
RUN apt-get install -y php-dev
RUN apt-get install -y php-gd
RUN apt-get install -y php-mbstring
RUN apt-get install -y php-zip
RUN apt-get install -y php-xml
RUN apt-get install -y php-soap
RUN apt-get install -y php-common
RUN apt-get install -y php-tokenizer
RUN apt-get install -y unzip
RUN apt-get install -y php-bcmath
RUN apt-get install -y php-mysql

# Install npm
RUN apt-get install -y npm
RUN npm cache clean -f
RUN npm install -g n
RUN n stable

RUN service apache2 restart

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

RUN echo " extension = php_mysqli.so"  >> /etc/php/8.1/apache2/php.ini

RUN service apache2 restart

CMD ( cron -f -l 8 & ) && apachectl -D FOREGROUND

数据库运行正常,速度良好。笔记本电脑性能不存在问题,因为之前部署的应用运行流畅无卡顿。


内容的提问来源于stack exchange,提问作者Negura Alexandru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:21:02