I have the following docker-compose file:

version: '2'

    driver: bridge


      context: .
      dockerfile: ./Dockerfile-app
      - "80:80"
      - default
      - yii2-db
      - "./app:/var/www/app"
      - "./nginx:/etc/nginx/sites-available"


FROM richarvey/nginx-php-fpm

ADD app /var/www/app

RUN rm -Rf /etc/nginx/sites-enabled/*

ADD nginx/site.conf /etc/nginx/sites-available/site.conf

RUN ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/site.conf

RUN cd /var/www/app && \
    composer install

RUN cd /var/www/app && chmod +x yii && \
    cd web && mkdir -p uploads && \
    cd /var/www && chown nginx:nginx -R app/

My last command RUN has no effect: chown does not set the nginx files owner. The folder "uploads" also is not created.

When I run docker-compose build --no-cache that step is passed:

Step 7/7 : RUN cd /var/www/app && chmod +x yii &&     cd web && mkdir -p uploads &&     cd /var/www && chown nginx:nginx -R app/
 ---> Running in 26a918bece47
Removing intermediate container 26a918bece47
 ---> 00db026a461c
Successfully built 00db026a461c
Successfully tagged passport-app_yii2-app:latest

However, when I run the workload in the "common" way using docker-compose up -d the change is not applied.

Why does my last RUN command not work?

  • I think you could try to debug those statements by executing them one by one and see if there is an issue.
    – profesor79
    Commented Aug 12, 2019 at 9:44
  • @profesor79 It seems like in Docker I can not create file (folder, make chown) in /var/www/app, because it's volume.
    – Log
    Commented Aug 12, 2019 at 10:00

2 Answers 2


Your mkdir and chown commands are RUN when building the image, whereas you then mount /var/www/app from a VOLUME, so you are replacing the created and chowned folder with the contents of ./app on the outside (and thus it's as if the chown didn't work).

If you want to chown the contents of the volume after it is mounted, you should place those instructions on a script that is called as the CMD.


I found the reason for the problem. In Docker

anything after the VOLUME instruction in a Dockerfile will not be able to make changes to that volume.

I define a volume with "./app:/var/www/app" and, after that, manipulate it, so it doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.