Lately, I’ve been trying to Dockerize my WordPress instance using 3 containers, one for nginx, another for mariadb and one for WordPress itself. But I simply can’t get it to work. For starters, every time WordPress has to call any plugin function it throws:
Fatal error: Uncaught Error: Call to undefined function
Besides, I can’t access some pages, for example if I try to access the index.php page I get page not found. However, I can access some pages directly, like wp-login.php.
Here is Nginx container:
Here is my WordPress container:
My docker-compose.yaml
version: '3.8'
services:
wp_db:
build: ./db
container_name: db_wp
restart: always
expose:
- 3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wpdb
MYSQL_USER: user
MYSQL_PASSWORD: password
wp:
depends_on:
- wp_db
image: wordpress:6.2.1-fpm-alpine
ports:
- "9000:9000"
container_name: wordpress
restart: unless-stopped
volumes:
- ./wp:/var/www/html
webserver:
depends_on:
- wp
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "81:80"
volumes:
- ./nginx:/etc/nginx/conf.d
- ./wp:/var/www/html
Here is my nginx.conf file:
server {
listen 80;
listen [::]:80;
access_log off;
root /var/www/html;
index index.php;
server_tokens off;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
location /wp-admin {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /wp-admin/index.php?$args;
}
# pass the PHP scripts to FastCGI server listening on wordpress:9000
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass wordpress:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
I tried changing ownership and permissions, but it still doesn’t work.