Docker Wordpress超级慢 [英] Docker Wordpress super slow

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

问题描述

我让WordPress在Docker内部运行,以进行本地开发,而且速度非常慢。我的docker-compose.yml看起来像这样:

I have Wordpress running inside Docker, for local development, and it's super slow. My docker-compose.yml looks like this:

version: '3.3'

services:
  db:
    image: mysql:5.7
    volumes:
      - ./db_data:/var/lib/mysql
      - ./dbconfig.cnf:/etc/mysql/conf.d/custom.cnf
    restart: always
    ports:
      - "3308:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: wp_database
      MYSQL_USER: db_user
      MYSQL_PASSWORD: some_secure_password

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "80:80"
      - "443:443"
    restart: always
    volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./.htaccess:/var/www/html/.htaccess
      - ./wp-config.php:/var/www/html/wp-config.php
      - ./logs/debug.log:/var/www/html/wp-content/debug.log
volumes:
  db_data: {}
  wp_content: {}

据我在网上阅读,这可能是我装入 wp-content 卷的原因,这会导致页面加载速度非常慢(加载每个文件大约需要半秒钟,例如一个jquery文件,并且必须为一页加载大量文件。)

As far as I read online, it might be the reason I am mounting the wp-content volume, which causes super slow page loading (takes like half a second to load each file, e.g. a jquery file, and it has to load a ton of files for one page).

有解决方案吗?我了解了NFS,但是使用docker-compose配置NFS不适用于我,因此我不断收到权限错误。另一方面,macOS的Docker界面已经向我显示了共享文件夹选项卡,但是我不知道我现在是在使用这些共享文件夹还是只是再次安装它们。

Is there a solution for this? I read about NFS, but it didn't work for me to configure NFS with docker-compose, somehow I keep getting "permission errors". On the other hand, the Docker interface of macOS already shows me a "Shared folder" tab but I don't know whether I am using those shared folders at the moment or just mounting them again.

感谢您的帮助。

推荐答案

TL; DR
安装到容器上的临时文件夹,将该文件夹与Bindfs同步到公用服务器文件夹。
使用直接挂载为WP站点提供服务的速度很慢,因为容器必须一个接一个地访问主机文件,这是一个繁重的过程。在文件直接属于容器的情况下从公共文件夹提供服务要快得多。

TL;DR Mount to temporary folder on container, sync that folder with Bindfs to public server folder. Serving WP site with direct mount is slow because container has to access Host files one by one, which is a heavy process. Serving from public folder while files being part directly of container is much faster.

我在Docker Compose开发中遇到了与本地WordPress完全相同的问题。不管您的计算机有多快,将文件夹安装到容器中时仍然很慢。

I've encountered exactly the same problem with local WordPress on Docker Compose development. It doesn't matter how fast your computer might be, it'll still be slow when mounting the folders in the containers.

我还尝试了NFS之类的解决方案以及其他建议,例如适当地排除了杀毒软件中的项目,添加.dockerignore等,充其量只能稍微改善性能。

I also tried solutions like NFS and other recommendations like properly excluding the project in the antivirus, adding .dockerignore, etc. which at best improve just slightly the performance.

在浏览速度类似的改进时,我在WordPress Starter存储库中遇到了这个Dockerfile https://github.com/visiblevc/wordpress-starter/blob/master/Dockerfile
如果您查看此文件,您会看到它们初始化并在容器中装入项目的方式是将其装入,而不是直接装入/ var / www / html /,而是装入一个临时文件夹。然后他们通过bindfs将此临时文件夹同步到/ var / www / html /。这样,每次您在浏览器中加载WordPress页面时,它都将快速运行,因为它不必每次请求都访问和读取Host文件。 WordPress文件是Linux容器的一部分。当您对代码进行更改时,这些更改将反映在容器临时文件夹上,bindfs将立即将这些更改同步到公共容器文件夹上,反之亦然。在公用文件夹上所做的所有更改都将同步到temp文件夹,并从那里同步到您的Host项目文件。

While browsing for a similar speed improvement I came across this Dockerfile at the WordPress Starter repository https://github.com/visiblevc/wordpress-starter/blob/master/Dockerfile. If you look at this file you'll see that the way they intialize and mount the project in the container is by mounting it not to, let's say, /var/www/html/ directly, but a temporary folder instead. Then they sync this temporary folder to /var/www/html/ through bindfs. This way every time you load a WordPress page in the browser it'll be lightning fast because it won't have to access and read the Host files on every request. The WordPress files are part of the Linux container. When you make changes to your code those changes will reflect on the container temporary folder and bindfs will instantly sync those changes over to the public container folder, and same the other way around. All changes made on the public folder will be synced over to the temp folder, and from there to your Host project files.

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

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