title: WP-CLI file permission problems using Docker volumes
body: <p><code>wordpress:cli</code> container is not able to manipulate files on a volume shared with <code>wordpress</code> container.</p>
  
  <p>Here's the <code>docker-compose.yml</code> file I use to bootstrap WordPress:</p>
  
  <pre><code>version: "3"
  
  services:
    wordpress:
      image: wordpress
      ports: ["80:80"]
      volumes: ["wp_test:/var/www/html"]
      environment:
        WORDPRESS_DB_NAME: wordpress
        WORDPRESS_DB_USER: root
        WORDPRESS_DB_PASSWORD: secret
  
    mysql:
      image: mysql
      environment:
        MYSQL_ROOT_PASSWORD: secret
  
    cli:
      image: wordpress:cli
      volumes: ["wp_test:/var/www/html"]
      command: sh -c "sleep 20 &amp;&amp; wp core install --path=/var/www/html --url=localhost --title=test --admin_user=test --admin_password=test --admin_email=test@example.com"
  
  volumes:
    wp_test:
  </code></pre>
  
  <p>I start it with <code>docker-compose up</code> and when <code>wp-cli</code> sets up the installation, there is a warning:</p>
  
  <pre><code>cli_1        | Warning: Unable to create directory wp-content/uploads/2018/02. Is its parent directory writable by the server?
  </code></pre>
  
  <p>The installation works so far, but I'd like to fix this warning, because for other <code>wp-cli</code> tasks manipulating files is critical.</p>
  
  <p>From inside <code>wordpress</code> container, privileges look like this:</p>
  
  <pre><code>drwxr-xr-x  5 www-data www-data  4096 Feb  2 11:21 .
  drwxr-xr-x  4 root     root      4096 Jan  4 01:30 ..
  -rw-r--r--  1 www-data www-data   234 Feb  2 11:21 .htaccess
  -rw-r--r--  1 www-data www-data   418 Sep 25  2013 index.php
  -rw-r--r--  1 www-data www-data 19935 Jan  6 19:32 license.txt
  -rw-r--r--  1 www-data www-data  7413 Dec 12  2016 readme.html
  -rw-r--r--  1 www-data www-data  5434 Sep 23 12:21 wp-activate.php
  drwxr-xr-x  9 www-data www-data  4096 Jan 16 21:39 wp-admin
  -rw-r--r--  1 www-data www-data   364 Dec 19  2015 wp-blog-header.php
  -rw-r--r--  1 www-data www-data  1627 Aug 29  2016 wp-comments-post.php
  -rw-r--r--  1 www-data www-data  2764 Feb  2 11:21 wp-config-sample.php
  -rw-r--r--  1 www-data www-data  3144 Feb  2 11:21 wp-config.php
  drwxr-xr-x  4 www-data www-data  4096 Feb  2 11:22 wp-content
  -rw-r--r--  1 www-data www-data  3669 Aug 20 04:37 wp-cron.php
  drwxr-xr-x 18 www-data www-data 12288 Jan 16 21:39 wp-includes
  -rw-r--r--  1 www-data www-data  2422 Nov 21  2016 wp-links-opml.php
  -rw-r--r--  1 www-data www-data  3306 Aug 22 11:52 wp-load.php
  -rw-r--r--  1 www-data www-data 36583 Oct 13 02:10 wp-login.php
  -rw-r--r--  1 www-data www-data  8048 Jan 11  2017 wp-mail.php
  -rw-r--r--  1 www-data www-data 16246 Oct  4 00:20 wp-settings.php
  -rw-r--r--  1 www-data www-data 30071 Oct 18 17:36 wp-signup.php
  -rw-r--r--  1 www-data www-data  4620 Oct 23 22:12 wp-trackback.php
  -rw-r--r--  1 www-data www-data  3065 Aug 31  2016 xmlrpc.php
  </code></pre>
  
  <p>but from within <code>cli</code> container the same volume looks like this:</p>
  
  <pre><code>drwxr-xr-x    5 www-data www-data      4096 Feb  2 11:21 .
  drwxr-xr-x    3 root     root          4096 Jan 10 07:36 ..
  -rw-r--r--    1 xfs      xfs            234 Feb  2 11:21 .htaccess
  -rw-r--r--    1 xfs      xfs            418 Sep 25  2013 index.php
  -rw-r--r--    1 xfs      xfs          19935 Jan  6 19:32 license.txt
  -rw-r--r--    1 xfs      xfs           7413 Dec 12  2016 readme.html
  -rw-r--r--    1 xfs      xfs           5434 Sep 23 12:21 wp-activate.php
  drwxr-xr-x    9 xfs      xfs           4096 Jan 16 21:39 wp-admin
  -rw-r--r--    1 xfs      xfs            364 Dec 19  2015 wp-blog-header.php
  -rw-r--r--    1 xfs      xfs           1627 Aug 29  2016 wp-comments-post.php
  -rw-r--r--    1 xfs      xfs           2764 Feb  2 11:21 wp-config-sample.php
  -rw-r--r--    1 xfs      xfs           3144 Feb  2 11:21 wp-config.php
  drwxr-xr-x    4 xfs      xfs           4096 Feb  2 11:22 wp-content
  -rw-r--r--    1 xfs      xfs           3669 Aug 20 04:37 wp-cron.php
  drwxr-xr-x   18 xfs      xfs          12288 Jan 16 21:39 wp-includes
  -rw-r--r--    1 xfs      xfs           2422 Nov 21  2016 wp-links-opml.php
  -rw-r--r--    1 xfs      xfs           3306 Aug 22 11:52 wp-load.php
  -rw-r--r--    1 xfs      xfs          36583 Oct 13 02:10 wp-login.php
  -rw-r--r--    1 xfs      xfs           8048 Jan 11  2017 wp-mail.php
  -rw-r--r--    1 xfs      xfs          16246 Oct  4 00:20 wp-settings.php
  -rw-r--r--    1 xfs      xfs          30071 Oct 18 17:36 wp-signup.php
  -rw-r--r--    1 xfs      xfs           4620 Oct 23 22:12 wp-trackback.php
  -rw-r--r--    1 xfs      xfs           3065 Aug 31  2016 xmlrpc.php
  </code></pre>
  
  <p>While user in <code>cli</code> container is <code>www-data</code> (just like it is in <code>wordpress</code> container), it cannot create the desired folder:</p>
  
  <pre><code>$ mkdir -p wp-content/uploads/2018/02
  mkdir: can't create directory 'wp-content/uploads/': Permission denied
  </code></pre>
  
  <p>I'm running docker compose 1.18.0 and and docker engine 17.12.0-ce on a mac.</p>
  
  <p>I also created <a href="https://github.com/docker-library/wordpress/issues/279" rel="noreferrer">a github issue</a>.</p>