WP-CLI-Dateiberechtigungsprobleme bei Verwendung von Docker-Volumes

Lesezeit: 3 Minuten

Benutzer-Avatar
Michail Vasin

wordpress:cli Container ist nicht in der Lage, Dateien auf einem Volume zu manipulieren, das mit geteilt wird wordpress Container.

Hier ist die docker-compose.yml Datei, die ich zum Bootstrap von WordPress verwende:

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:

Ich fange damit an docker-compose up und wann wp-cli die Installation einrichtet, gibt es eine Warnung:

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

Die Installation funktioniert soweit, aber ich möchte diese Warnung beheben, da für andere wp-cli Aufgaben, die Dateien manipulieren, ist kritisch.

Von innen wordpress Container, Berechtigungen sehen so aus:

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

sondern von innen cli Container das gleiche Volumen sieht so aus:

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

Während der Benutzer drin ist cli Behälter ist www-data (so wie es drin ist wordpress Container), kann der gewünschte Ordner nicht erstellt werden:

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

Ich verwende Docker Compose 1.18.0 und Docker Engine 17.12.0-ce auf einem Mac.

habe ich auch erstellt ein Github-Problem.

Ich nehme an, Ihre Frage lautet: “Wie behebe ich WP-CLI-Dateiberechtigungsprobleme mit Docker-Volumes?”

Sie müssen sicherstellen, dass wp-cli in beiden Containern mit derselben UID ausgeführt wird.

Von der Befehlszeile:

docker run -it --rm \
    --volumes-from $container \
    --network container:$container \
    --user 33:33 \
    wordpress:cli core install --path=/var/www/html --url=localhost --title=test --admin_user=test --admin_password=test [email protected]

--user 33:33 ist eine Problemumgehung, um wp-cli mit derselben UID/GID wie www-data im WordPress-Container auszuführen. Probleme entstehen, weil die Container unterschiedliche UID/GID für www-Daten haben. Sehen https://github.com/docker-library/wordpress/issues/256

Sie sollten in der Lage sein, hinzuzufügen user: "33:33" auch in Ihre Docker-Compose-Datei. Sehen https://github.com/docker/compose/issues/1532

1371650cookie-checkWP-CLI-Dateiberechtigungsprobleme bei Verwendung von Docker-Volumes

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy