WP-CLI file permission problems using Docker volumes

admin

Administrator
Staff member
Code:
wordpress:cli
container is not able to manipulate files on a volume shared with
Code:
wordpress
container.

Here's the
Code:
docker-compose.yml
file I use to bootstrap WordPress:

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 && wp core install --path=/var/www/html --url=localhost --title=test --admin_user=test --admin_password=test [email protected]"

volumes:
  wp_test:

I start it with
Code:
docker-compose up
and when
Code:
wp-cli
sets up the installation, there is a warning:

Code:
cli_1        | Warning: Unable to create directory wp-content/uploads/2018/02. Is its parent directory writable by the server?

The installation works so far, but I'd like to fix this warning, because for other
Code:
wp-cli
tasks manipulating files is critical.

From inside
Code:
wordpress
container, privileges look like this:

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

but from within
Code:
cli
container the same volume looks like this:

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

While user in
Code:
cli
container is
Code:
www-data
(just like it is in
Code:
wordpress
container), it cannot create the desired folder:

Code:
$ mkdir -p wp-content/uploads/2018/02
mkdir: can't create directory 'wp-content/uploads/': Permission denied

I'm running docker compose 1.18.0 and and docker engine 17.12.0-ce on a mac.

I also created <a href="https://github.com/docker-library/wordpress/issues/279" rel="noreferrer">a github issue</a>.