douneiben2240 2019-03-17 17:31
浏览 259

Docker for Windows上的Laravel应用程序性能问题

I am trying to run my laravel application inside docker containers on my laptop (during development) and finding that the speed of the application is drastically slow when compared to running it using XAMPP for example.

My laptop is running Windows 10 Pro (64-Bit) with i7-6700HQ CPU, 16 GB RAM and SSD.

When I run my app in docker for windows, average page load time is approx 3.5 Seconds.

Running it on local XAMPP, average page load time is approx 350 Milliseconds (0.35 Second).


For my docker setup, I use the following image/Dockerfile:

FROM alpine:3.8
MAINTAINER Latheesan Kanesamoorthy

RUN apk add \
        --no-cache \
        --update \
        apache2 \
        composer \
        curl \
        php7 \
        php7-apache2 \
        php7-curl \
        php7-bcmath \
        php7-dom \
        php7-mbstring \
        php7-pdo_mysql \
        php7-session \
        php7-sockets \
        php7-tokenizer \
        php7-xml \
        php7-xmlwriter \
        php7-fileinfo \
    && mkdir -p /run/apache2 \
    && ln -sf /dev/stdout /var/log/apache2/access.log \
    && ln -sf /dev/stderr /var/log/apache2/error.log

COPY ./image/*.conf /etc/apache2/conf.d/
COPY ./image/php.ini /etc/php7/conf.d/99_custom.ini

RUN mkdir -p /storage/framework/testing
RUN mkdir -p /storage/framework/views
RUN mkdir -p /storage/framework/sessions
RUN mkdir -p /storage/framework/cache/data
RUN chown -R apache:apache /storage

WORKDIR /app

COPY ./src/composer.* ./
RUN composer install -n --no-autoloader --no-scripts --no-progress --no-suggest

COPY src .
RUN composer dump-autoload -o -n

EXPOSE 80

and docker-compose.yml:

version: '2.1'

services:

  mysql:
    container_name: myapp-mysql
    mem_limit: 512M
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: myapp
      MYSQL_DATABASE: myapp
      MYSQL_USER: myapp
      MYSQL_PASSWORD: myapp
    ports:
      - "35000:3306"

  redis:
    container_name: myapp-redis
    image: redis:latest

  redis-commander:
    container_name: myapp-redis-commander
    image: rediscommander/redis-commander:latest
    hostname: redis-commander
    restart: always
    environment:
      - REDIS_HOSTS=local:redis:6379
    ports:
      - "7050:8081"
    links:
      - redis

  app:
    container_name: myapp-app
    mem_limit: 512M
    build:
      context: ""
      dockerfile: image/Dockerfile
    env_file:
    - image/env/development
    volumes:
    - ./src:/app:cached
    ports:
      - "25000:80"
    entrypoint: httpd -DFOREGROUND
    links:
      - mysql
      - redis

and I use the following commands to boot it up:

docker-compose down --remove-orphans
docker-compose up -d --build
docker exec myapp-app composer install --prefer-dist --no-suggest
docker exec myapp-app php artisan cache:clear
docker exec myapp-app php artisan migrate:fresh --seed

As you can see, the docker version uses redis as the driver for: cache, eloquent model cache, queue and session.

Locally for XAMPP, I am simply using file driver for all.

Any idea why the performance is so slow on docker?

P.S. The reason why I want to try developing using the docker environment is so that I can keep my development and production environment identical.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用