WordPress的Docker速度慢 [英] Docker for WordPress slow

查看:113
本文介绍了WordPress的Docker速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我在WordPress&上有问题Docker,因为我的网站加载时间缓慢(+-7秒).我不确定为什么会发生这种情况,但我认为这与外部数据库或共享卷有关.

设置:

我有一个基于WordPress的自定义Dockerfile,带有XDebug和Mailhog.该Dockerfile包含在我的docker-compose.yml中,我的docker-compose包含的其他服务是WP-CLI和Mailhog.我的数据库托管在Amazon RDS上,因此我可以与同事共享.

代码:

我的Dockerfile看起来像这样:

  FROM wordpress:latest#插件和媒体运行mkdir -p/var/www/html/wp-content/plugins运行mkdir -p/var/www/html/wp-content/uploadsRUN chown -R www-data:www-data/var/www运行查找/var/www/-type d -exec chmod 0755 {} \;运行查找/var/www/-type f -exec chmod 644 {} \;#Mailhog运行curl --location --output/usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64&&\chmod + x/usr/local/bin/mhsendmailRUN echo'sendmail_path ="/usr/local/bin/mhsendmail --smtp-addr = mailhog:1025 --from=noreply@examle.com"'>/usr/local/etc/php/conf.d/mailhog.ini#XdebugENV XDEBUG_PORT 9000运行是|pecl安装xdebug&&echo"zend_extension = $(找到/usr/local/lib/php/extensions/-name xdebug.so)">/usr/local/etc/php/conf.d/xdebug.ini \&&回声"xdebug.remote_enable = 1">>/usr/local/etc/php/conf.d/xdebug.ini \&&回声"xdebug.remote_autostart = 1">>/usr/local/etc/php/conf.d/xdebug.ini \&&回声"xdebug.profiler_enable = 1">>/usr/local/etc/php/conf.d/xdebug.ini \&&回声"xdebug.profiler_output_name = cachegrind.out.%t">>/usr/local/etc/php/conf.d/xdebug.ini \&&回声"xdebug.profiler_output_dir =/tmp">>/usr/local/etc/php/conf.d/xdebug.ini \&&回声"max_input_vars = 2000">>/usr/local/etc/php/conf.d/custom.ini \&&rm -rf/usr/local/etc/php/conf.d/opcache-recommended.ini9000博览会 

我的Docker-compose.yml看起来像这样:

 版本:"3.7"服务:WordPress的:container_name:"$ {PROJECT_NAME} _wordpress"重启:总是建造:语境: ./dockerfile:./Dockerfile端口:-"8888:80"-"443:443"环境:WORDPRESS_DB_NAME:"$ {PROJECT_NAME}"WORDPRESS_DB_HOST:"$ {MYSQL_HOST}"WORDPRESS_DB_USER:"$ {MYSQL_USER}"WORDPRESS_DB_PASSWORD:"$ {MYSQL_PASSWORD}"WORDPRESS_DEBUG:1XDEBUG_CONFIG:remote_host = host.docker.internalWORDPRESS_CONFIG_EXTRA:define('FS_METHOD','direct');数量:-"wordpress:/var/www/html"-"./build/uploads:/var/www/html/wp-content/uploads:cached"-"./build/plugins:/var/www/html/wp-content/plugins:cached"-"./build/themes:/var/www/html/wp-content/themes:cached"cli:container_name:"$ {PROJECT_NAME} _cli"图片:"wordpress:cli"数量:-"wordpress:/var/www/html"-"./build/plugins:/var/www/html/wp-content/plugins:cached"取决于:-WordPress的mailhog:container_name:"$ {PROJECT_NAME} _mailhog"图片:mailhog/mailhog取决于:-WordPress的端口:-"1025:1025"-"8025:8025"数量:wordpress:null 

但是我不知道为什么它这么慢.我有Docker Desktop的2.1.09.3版本,并且可以在快速的Mac或Windows上工作.

有人可以帮助我或为我指明正确的方向吗?

编辑

  1. 如果我查看docker stats,我的CPU约为0.01%,我的MEM约为2.73%,所以这不是问题.
  2. 发现最大的问题是连接到外部数据库.如果我移到本地数据库,则加载时间要快得多(+1秒).

解决方案

Mac&Windows卷性能.

链接以获取更多详细信息:

Docker Wordpress超级慢


在Mac和Windows中,存在一些音量性能问题我们应该考虑的.

我在 docker-compose.yml

中进行了更改

请注意,我将短语法更改为长语法./p>

此符号允许添加一致性选项.

我添加了 wp-content php-conf (以获取php.ini),因为它们是每次加载Wordpress页面时最常调用的文件目录浏览器.

 服务:WordPress的:...数量:-./data:/数据-./脚本:/docker-entrypoint-initwp.d#-./wp-content:/app/wp-content-类型:绑定来源:./wp-content目标:/app/wp-content一致性:已缓存#-./php-conf:/usr/local/etc/php-类型:绑定来源:./php-conf目标:/usr/local/etc/php一致性:已缓存 

Problem:

I have a problem with WordPress & Docker because the slow loading time (+- 7 seconds) of my website. I am not sure why this happends but I think it has something to do with the external database or the shared volumes.

Setup:

I have a custom Dockerfile built on WordPress with XDebug and Mailhog. This Dockerfile is included within my docker-compose.yml, the other services my docker-compose contains are WP-CLI and Mailhog. My Database is hosted on an Amazon RDS so I can share it with my colleagues.

Code:

My Dockerfile looks like this:

FROM wordpress:latest

# Plugins & Media
RUN mkdir -p /var/www/html/wp-content/plugins
RUN mkdir -p /var/www/html/wp-content/uploads

RUN chown -R www-data:www-data /var/www

RUN find /var/www/ -type d -exec chmod 0755 {} \;
RUN find /var/www/ -type f -exec chmod 644 {} \;

# Mailhog
RUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && \
    chmod +x /usr/local/bin/mhsendmail

RUN echo 'sendmail_path="/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 --from=noreply@examle.com"' > /usr/local/etc/php/conf.d/mailhog.ini

# Xdebug
ENV XDEBUG_PORT 9000

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.profiler_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.profiler_output_name=cachegrind.out.%t" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.profiler_output_dir=/tmp" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "max_input_vars=2000" >> /usr/local/etc/php/conf.d/custom.ini \
    && rm -rf /usr/local/etc/php/conf.d/opcache-recommended.ini

EXPOSE 9000

My Docker-compose.yml looks like this:

version: "3.7"
services:
    wordpress:
        container_name: "${PROJECT_NAME}_wordpress"
        restart: always
        build:
            context: ./
            dockerfile: ./Dockerfile
        ports:
            - "8888:80"
            - "443:443"
        environment:
            WORDPRESS_DB_NAME: "${PROJECT_NAME}"
            WORDPRESS_DB_HOST: "${MYSQL_HOST}"
            WORDPRESS_DB_USER: "${MYSQL_USER}"
            WORDPRESS_DB_PASSWORD: "${MYSQL_PASSWORD}"
            WORDPRESS_DEBUG: 1
            XDEBUG_CONFIG: remote_host=host.docker.internal
            WORDPRESS_CONFIG_EXTRA: |
                define('FS_METHOD', 'direct');
        volumes:
            - "wordpress:/var/www/html"
            - "./build/uploads:/var/www/html/wp-content/uploads:cached"
            - "./build/plugins:/var/www/html/wp-content/plugins:cached"
            - "./build/themes:/var/www/html/wp-content/themes:cached"
    cli:
        container_name: "${PROJECT_NAME}_cli"
        image: "wordpress:cli"
        volumes:
            - "wordpress:/var/www/html"
            - "./build/plugins:/var/www/html/wp-content/plugins:cached"
        depends_on:
            - wordpress
    mailhog:
        container_name: "${PROJECT_NAME}_mailhog"
        image: mailhog/mailhog
        depends_on:
            - wordpress
        ports:
            - "1025:1025"
            - "8025:8025"
volumes:
    wordpress: null

But I can't find out why it is so slow; I got version 2.1.09.3 of Docker Desktop and working on a fast Mac or Windows.

Can someone help me or point me in the right direction?

Edits

  1. If I look in the docker stats my CPU is around 0.01% and my MEM is around 2.73% so that can't be the problem.
  2. Found out the biggest problem is connecting to the external database. If I move over to a local database the loading time is a lot faster (+- 1 sec).

解决方案

There some issues for Mac & Windows Volume performance.

Link for more details:

Docker Wordpress super slow


In Mac and Windows there are some volumes performance issues that we should consider.

I made change in my docker-compose.yml

Note as I changed the short syntax to long syntax.

This notation permits add consistency option.

I added wp-content and php-conf (to get php.ini) because they are files directory most frequently called every time when a Wordpress page is loaded in browser.

services:
    wordpress:

        ...

        volumes:
            - ./data:/data
            - ./scripts:/docker-entrypoint-initwp.d
            #- ./wp-content:/app/wp-content
            - type: bind
              source: ./wp-content
              target: /app/wp-content
              consistency: cached
            #- ./php-conf:/usr/local/etc/php
            - type: bind
              source: ./php-conf
              target: /usr/local/etc/php
              consistency: cached

这篇关于WordPress的Docker速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆