PHP - Failed to open stream: Permission denied while uploading image

Trying to upload an image in PHP, I’m receiving an error: Warning: move_uploaded_file(…/upload/ferrari_logo.jpg): Failed to open stream: Permission denied in /var/www/html/mypage.php on line 108

Warning: move_uploaded_file(): Unable to move “/tmp/php8hHG6L” to “…/upload/ferrari_logo.jpg” in /var/www/html/mypage.php on line 108

I know I have to change the permission in the upload folder. I just wanted to know if how can I change these permissions in Docker?

mypage.php

<div class="photo_column">
<form method="post" id="upload_form" action="mypage.php" enctype="multipart/form-data">
    <div id="about_me_photo">

    <?php
        $message = '';
        $moved = false;

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if ($_FILES['photo_upload']['error'] === 0) {
                $temp = $_FILES['photo_upload']['tmp_name'];
                $path = '../upload/' . $_FILES['photo_upload']['name'];
                $moved = move_uploaded_file($temp, $path);
            } 

            if ($moved === true) {
                echo '<img id="about_me_img" src="' . $path . '"alt="">';
            } else {
                echo '<img id="about_me_img" src="" alt="">';
            }
        } else {
            echo '<img id="about_me_img" src="" alt="">';
        }

    ?>
            <div class="about_me_row">
                <input type="file" id="photo_upload" name="photo_upload" accept="image/*">
                <input type="submit" class="mypage_button"  id="submit_photo" value="Upload">
            </div>
            
        
    </div>
</form>
</div>

docker-compose.yml

services:
  php-apache:
    ports:
      - "8000:80"
    build: './build/php'
    volumes:
      - ./app/public:/var/www/html
      - ./src:/var/www/src
      - ./config:/var/www/config
      - ./upload:/var/www/upload
      - ./img:/var/www/img
  mysql:
    image: mysql:latest
    ports:
      - "3306:3306"
    build: './build/mysql'
    environment:
      MYSQL_ROOT_PASSWORD: "password"
      MYSQL_DATABASE: "commune"
    volumes:
      - dbData:/var/lib/mysql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
    depends_on:
      - mysql
    restart: always
    ports:
      - 8080:80
volumes:
  app:
  src:
  config:
  upload:
  img:
  dbData:

Dockerfile

FROM php:8.1-apache

RUN apt-get update && \
    docker-php-ext-install mysqli pdo pdo_mysql

ARG USERNAME=hippie
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME

I hope this code will help you.

services:
  php-apache:
    ports:
      - "8000:80"
    build: './build/php'
    volumes:
      - ./app/public:/var/www/html
      - ./src:/var/www/src
      - ./config:/var/www/config
      - ./upload:/var/www/upload
      - ./img:/var/www/img
    command: /bin/sh -c "chmod -R 777 /var/www/upload && apache2-foreground"

I entered the command line in to my docker-compose.yml file but I’m getting this line when I run docker:
php-apache-1 | chmod: changing permissions of ‘/var/www/upload’: Operation not permitted

Localhost:8000 doesn’t appear when I included the line and when I comment it out, it runs again.

Is there something I can do to fix it? Thank you

I added “sudo” after command and the errors clear up. I guess have to figure out how to display the images. Thank you