'Docker nginx container with wordpress uploads folder on volume, can't upload files due to permission denied

I have an nginx container running wordpress (using docker compose) and the uploads folder assigned to a volume:

vipirs-uploads:/usr/share/nginx/html/website/wp-content/uploads

I can't upload files:

Unable to create directory wp-content/uploads/2022/05. Is its parent directory writable by the server?

So the actual uploads folder doesn't exist on the host machine.

Normally i would simply set the correct permissions but in this case i'm not sure how i would go about this. As a test i tried setting chmod to 777 on the folder inside the container but that didn't work.

My docker-compose.yml:

version: '3.7'
services:
  rhino-php:
    platform: linux/amd64
    build:
      context: ./docker
      dockerfile: Dockerfile-php7.4
    image: rhino-php
    container_name: rhino-php
    volumes:
      - ./Vipirs-Website:/usr/share/nginx/html
    ports:
      - 9000
    networks:
      - vipirs-net
  rhino-proxy:
    platform: linux/amd64
    image: nginx:alpine
    container_name: rhino-proxy
    depends_on:
      - vipirs-website
    volumes:
      - ./docker/nginx/proxy-live.conf:/etc/nginx/nginx.conf
      - /usr/local/share/sites/vipirs.com/docker/ssl/live:/usr/local/etc/ssl/certs
    ports:
      - 80:80
      - 443:443
    networks:
      - vipirs-net
  vipirs-website:
    platform: linux/amd64
    image: nginx
    container_name: vipirs-website
    depends_on:
      - rhino-php
      - vipirs-website-database
    volumes:
      - ./docker/nginx/site-live.conf:/etc/nginx/conf.d/default.conf
      - ./Vipirs-Website:/usr/share/nginx/html
      - ./Vipirs-Website/logs/wp-debug.log:/usr/share/nginx/html/website/wp-content/debug.log
      - vipirs-uploads:/usr/share/nginx/html/website/wp-content/uploads
      - /usr/local/share/sites/vipirs.com/docker/ssl/live:/usr/local/etc/ssl/certs
    ports:
      - 80
      - 443
    links:
      - rhino-php
    networks:
      - vipirs-net

  vipirs-website-database:
    platform: linux/amd64
    image: mysql:5.7
    container_name: vipirs-db
    environment:
      MYSQL_ROOT_PASSWORD: vipirs
      MYSQL_DATABASE: vipirs
      MYSQL_USER: vipirs
      MYSQL_PASSWORD: vipirs
    volumes:
      - ./Vipirs-Website/db:/usr/share/db
      - vipirs-db:/var/lib/mysql
    restart: always
    ports:
      - 3306
    networks:
      - vipirs-net
networks:
  vipirs-net:
volumes:
  vipirs-uploads:
  vipirs-db:


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source