2

I've set up a docker-compose with wordpress, nginx and mysql containers.

Everything is working fine besides the uploading of images. When I upload images they don't get saved in either of the container's /uploads folder, and just show a blank image on wp-admin.

blank image

If I try to access the image url directly it returns 404.

404

I've found 3 (post 1, post 2 & post 3) related posts, but none of them gave me any insights to this problem.

This is my docker-compose:

version: '3.1'

services:
  wordpress:
    image: wordpress:fpm-alpine
    depends_on:
      - db
    restart: always
    env_file: 
    - .env
    ports:
      - 9000:9000
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: ${DB_USER}
      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
      WORDPRESS_DB_NAME: ${DB}
      WORDPRESS_DEBUG: ${DEBUG}
      WORDPRESS_DEBUG_DISPLAY: ${DEBUG}
      WORDPRESS_DEBUG_LOG: ${DEBUG}
    volumes:
      - ./theme-folder:/var/www/html/wp-content/themes/theme-folder

  db:
    image: mysql:5.7
    restart: always
    env_file: 
    - .env
    environment:
      MYSQL_DATABASE: ${DB}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    volumes:
      - db:/var/lib/mysql

  webserver:
    image: nginx:alpine
    depends_on:
      - wordpress
    ports:
      - 8080:80
      - 443:443
    volumes:
      - ./nginx-conf:/etc/nginx/conf.d
      - wordpress:/var/www/html
      - ./theme-folder:/var/www/html/wp-content/themes/theme-folder
      - ./pem/fullchain.pem:/etc/letsencrypt/live/website/fullchain.pem
      - ./pem/privkey.pem:/etc/letsencrypt/live/website/privkey.pem

volumes:
  wordpress:
  db:

This is my nginx.conf:

server {
    listen 80;
    listen [::]:80;
    server_name website;
    root /var/www/html;
    index index.php index.html index.htm;

    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;
    }

    location / {
            rewrite ^ https://$host$request_uri? permanent;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name website;
    root /var/www/html;
    index index.php index.html index.htm;

    ssl_certificate /etc/letsencrypt/live/website/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/website/privkey.pem;

    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;
    }
}

Really appreciate any insights, I've been stuck here for days now.

Updates

Tried tailing docker logs, but didn't help much.

wordpress container logs

Also, tried adding this to my nginx.conf:

location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;
}
motizukilucas
  • 103
  • 1
  • 6
  • I'm running into this as well. Did you resolve it? – bonhoffer Dec 25 '22 at 20:19
  • @bonhoffer did not. I ended up doing what's right and quitting wordpress xDD – motizukilucas Dec 25 '22 at 20:24
  • Out of curiosity, why do you load `nginx:alpine` and `wordpress:fpm-alpine` containers instead of the standalone `wordpress` image? I only ask because I deploy all my local wp projects using docker hubs wp official image.. without any other images apart from `mysql` etc. Why do we need image `nginx:alpine`? I'm curious... thanks! – joshmoto Dec 26 '22 at 01:11
  • @joshmoto tbh I can't remember why at this point, but prob to have nginx as the entry point to the server – motizukilucas Dec 29 '22 at 22:23

0 Answers0