Docker does not set permissions on a folder in volume

Hello.
I have this docker-compose.yml:

version: '2'
services:
  php:
    build: .
    volumes:
      - ./web/uploads:/app/web/uploads:delegated
    ports:
      - '8000:80'

And Dockerfile:

FROM yiisoftware/yii2-php:8.1-apache
COPY ./base.ini /usr/local/etc/php/conf.d/base.ini
COPY . /app
WORKDIR /app
RUN composer install
RUN chown -R www-data:www-data /app 
RUN chmod o+w /app/web/uploads && chmod o+w /app/web/uploads/result

After I cloned this repository from github a folder ‘uploads’ will have my ubuntu owner and group and rights - rwxrwxr-x. Inside container it will have 1000:1000 ownership.

Inside container we have apache user - www-data - who cannot write to the directory ‘uploads’. Somehow the last line in Dockerfile has no effect.

I would like to lanch application with one command - docker compose up -d, after I got app’s files.
Any suggestions how to do it? Thanks.

Of course, it doesn’t work like this, if you bind the host folder ./web/uploads/ into the container folder /app/web/uploads, it eclipses the original content from the container filesystem. You need to fix the permissions on the host folder ./web/uploads/.

Note: a bind volume mounts the inode (~=location in the filesystem) of the host folder additionally into the container folder, so that both can access the same physical data.

I hope it makes sense.

1 Like