Docker for WordPress slow

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 [email protected]"' > /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?

Source: StackOverflow