I am trying to setup a local development environment to locally develop a plugin and theme for a Wordpress site. I’ve used different setups with docker-compose but encountered serious performance issues locally. Recently I am using Local wordpress dev example and that works like a charm. Except for one thing. It seems that the local mounted file (src and import) is not accessible by the Nginx container. I am running the latest version of Docker desktop (4.34.2) for Windows (11).
I run the docker image using the following docker-compose.yml file:
services:
nginx:
container_name: ${CONTAINER_NAME}-nginx
build:
context: .
dockerfile: ./nginx/Dockerfile
restart: unless-stopped
env_file: .env
environment:
HOSTNAME: ${HOSTNAME}
ports:
- "80:80"
- "443:443"
volumes:
- wordpress:/var/www/html
networks:
- internal
database:
container_name: ${CONTAINER_NAME}-database
image: mysql:8.0
restart: unless-stopped
env_file: .env
environment:
MYSQL_DATABASE: ${DATABASE_NAME}
MYSQL_PASSWORD: ${DATABASE_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD}
MYSQL_USER: ${DATABASE_USER}
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-p$$DATABASE_ROOT_PASSWORD" ]
timeout: 20s
retries: 10
ports:
- "3306:3306"
volumes:
- dbdata:/var/lib/mysql
networks:
- internal
phpmyadmin:
container_name: ${CONTAINER_NAME}-phpmyadmin
image: phpmyadmin/phpmyadmin
env_file: .env
environment:
PMA_HOST: database
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: "${DATABASE_ROOT_PASSWORD}"
ports:
- "8081:80"
networks:
- internal
wordpress:
depends_on:
- database
container_name: ${CONTAINER_NAME}-wordpress
image: wordpress:6.6.2-fpm-alpine
restart: unless-stopped
env_file: .env
environment:
WORDPRESS_DB_HOST: database:3306 # use the same name as database service
WORDPRESS_DB_NAME: '${DATABASE_NAME}'
WORDPRESS_DB_USER: '${DATABASE_USER}'
WORDPRESS_DB_PASSWORD: '${DATABASE_PASSWORD}'
WORDPRESS_DEBUG: 1
volumes:
- wordpress:/var/www/html
- ./src:/var/www/html/wp-content:rw
- ./import:/var/www/html/import:rw
networks:
- internal
volumes:
dbdata:
wordpress:
networks:
internal:
driver: bridge
With the following Nginx config:
upstream php {
server unix:/tmp/php-cgi.socket;
server wordpress:9000;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80; ## listen for ipv6
server_name ${HOSTNAME};
root /var/www/html;
location / {
index index.php index.html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
When accessing the /wp-content file in the browser is shows a 403 permission denied:
403 Forbidden / nginx/1.27.1
Also the directory is empty when check the files in the Nginx container (same is the case for the import folder). The Wordpress container is able to list all the files. This makes that the Wordpress installation is running, but it is not able to for instance show images.
I’ve tried to rebuild the containers. Also clean with no cache. I’ve also made sure that the owner and permissions of the folder are the same (upon build they are assigned to root instead of www-data).
I’ve ran following commands in Wordpress container:
$ chown -R www-data:www-data /var/www/html/wp-content/
$ chmod -R 755 /var/www/html/wp-content/
However, files are still not mirrored in the Nginx container and both folders (wp-content + import) remain empty in the Nginx container, and therefore not accessible via the browser.
Any suggestion how to fix this issue?