Answers: <p>you need to create the www-data user in the dockerfile eg</p>
  <pre><code>RUN addgroup -g 1000 www-data &amp;&amp; adduser -G www-data -g www-data -s /bin/sh -D www-data
  
  RUN chown -R www-data:www-data /home/www-data &amp;&amp; \
      chown -R www-data:www-data /var/www
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-05-14T09:57:18.763Z
Answers: 2021-05-14T09:57:18.763Z
Answers: Jerry Chen
Body: <p>I have this service in my <code>docker-compose.yml</code></p>
  <p>php-fpm:
  container_name: php_app
  restart: always
  build:
  context: .
  dockerfile: ./docker/php-fpm/Dockerfile
  volumes:
  - ./src:/var/www/html</p>
  <p>that take everything of the host folder <code>src</code> and add to <code>/var/www/html</code>:</p>
  <pre><code>FROM php:8.0.2-fpm-alpine
  WORKDIR /var/www/html
  
  RUN docker-php-ext-install pdo_mysql
  RUN docker-php-ext-install mysqli
  RUN apk add icu-dev
  
  COPY docker/php-fpm/config/php.ini /usr/local/etc/php/
  
  RUN apk add --update nodejs nodejs-npm
  RUN npm install gulp-cli -g
  RUN npm install
  
  COPY src src/
  
  CMD [&quot;php-fpm&quot;]
  
  EXPOSE 9000
  </code></pre>
  <p>accessing the container using <code>sudo docker exec -it php_app sh </code> and executing <code>ls -la</code> I have:</p>
  <p>drwxrwxr-x    6 1001     1001          4096 May 12 15:54 writable</p>
  <p>which must be owned by <code>www-data</code>, how can I set the ownership automatically when the builds complete?</p>
  
Tags: <docker><docker-compose>
Title: How to change ownership of folder inside the container after build?
UserDisplayName: sfarzoso
ThreadText: # How to change ownership of folder inside the container after build?
  
  (Asked by: username_0 on 2021-05-12)
  
  I have this service in my `docker-compose.yml`
  
  php-fpm:
  container\_name: php\_app
  restart: always
  build:
  context: .
  dockerfile: ./docker/php-fpm/Dockerfile
  volumes:
  - ./src:/var/www/html
  
  that take everything of the host folder `src` and add to `/var/www/html`:
  
  ```
  FROM php:8.0.2-fpm-alpine
  WORKDIR /var/www/html
  
  RUN docker-php-ext-install pdo_mysql
  RUN docker-php-ext-install mysqli
  RUN apk add icu-dev
  
  COPY docker/php-fpm/config/php.ini /usr/local/etc/php/
  
  RUN apk add --update nodejs nodejs-npm
  RUN npm install gulp-cli -g
  RUN npm install
  
  COPY src src/
  
  CMD ["php-fpm"]
  
  EXPOSE 9000
  
  ```
  
  accessing the container using `sudo docker exec -it php_app sh`  and executing `ls -la` I have:
  
  drwxrwxr-x 6 1001 1001 4096 May 12 15:54 writable
  
  which must be owned by `www-data`, how can I set the ownership automatically when the builds complete?
  
  **Tags:** docker, docker-compose
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-05-14. Score: 1 | Accepted answer
  
  you need to create the www-data user in the dockerfile eg
  
  ```
  RUN addgroup -g 1000 www-data && adduser -G www-data -g www-data -s /bin/sh -D www-data
  
  RUN chown -R www-data:www-data /home/www-data && \
      chown -R www-data:www-data /var/www
  
  ```
  
  
  ---
  
  