I’m using Docker to contain a WordPress site (on localhost) for a team demo project. Our setup includes:
- MySQL database hosted on Azure.
- WordPress files stored on GitHub, copied into the container’s WordPress folder during the build process.
Issue: The site is extremely slow (10+ seconds to load each page), including the admin page. Redis cache reduced the load time by a couple of seconds, but it’s still unacceptably slow.
Observation: When loading a page, the initial request (e.g., http://localhost/) remains in a ‘pending’ state for several seconds with no logs in the Docker container. Once the request resolves, the data is received, and the container logs the request.
Dockerfile:
# Use the official PHP image with Apache
FROM php:8.0-apache
# Use a bash shell for execution
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends
bash-completion
bindfs
ghostscript
less
libjpeg-dev
libmagickwand-dev
libpng-dev
libxml2-dev
libzip-dev
mariadb-client
sudo
unzip
vim
zip
curl
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
# Configure GD with JPEG and Freetype support
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
&& docker-php-ext-install -j$(nproc) gd
# Install PHP extensions
RUN docker-php-ext-install bcmath exif mysqli opcache soap zip
&& pecl install redis
&& docker-php-ext-enable redis
# Copy the WordPress files
WORKDIR /var/www/html
COPY src/ /var/www/html/
# Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html
# Expose ports for Apache
EXPOSE 80 443
# Start Apache in foreground
CMD ["apache2-foreground"]
docker-compose.yml:
version: '3.8'
services:
wordpress:
build: .
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
env_file:
- .env
restart: always
networks:
- wp-network
depends_on:
- redis
dns:
- 8.8.8.8
- 8.8.4.4
redis:
image: redis:latest
networks:
- wp-network
ports:
- "6379:6379"
dns:
- 8.8.8.8
- 8.8.4.4
networks:
wp-network:
driver: bridge
Troubleshooting Steps Taken:
- Implemented Redis cache – minor improvement.
- Adjusted Dockerfile and docker-compose.yml to add volumes and DNS resolver – no significant impact.
Questions:
What could be causing the initial request to remain in a ‘pending’ state for so long?
Are there any optimizations or configurations I should consider to reduce the load times?
Any advice or insights would be greatly appreciated.