Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress on Docker: Could not create directory on mounted volume

Here is are the original files in the Wordpress Docker container on path /var/www/html:

$ docker exec 5b957c7b9c5ad054883694afbfb80d3c9df6707458d55011f471be0701f3890c ls -l
total 192
-rw-r--r--  1 www-data www-data   418 Sep 25  2013 index.php
-rw-r--r--  1 www-data www-data 19935 Jan  2 18:51 license.txt
-rw-r--r--  1 www-data www-data  7433 Jan 11 17:46 readme.html
-rw-r--r--  1 www-data www-data  5447 Sep 27  2016 wp-activate.php
drwxr-xr-x  9 www-data www-data  4096 May 16 21:50 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 May 29 22:19 wp-config-sample.php
-rw-r--r--  1 www-data www-data  3148 May 29 22:19 wp-config.php
drwxr-xr-x  4 www-data www-data  4096 May 16 21:50 wp-content
-rw-r--r--  1 www-data www-data  3286 May 24  2015 wp-cron.php
drwxr-xr-x 18 www-data www-data 12288 May 16 21:50 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  3301 Oct 25  2016 wp-load.php
-rw-r--r--  1 www-data www-data 33939 Nov 21  2016 wp-login.php
-rw-r--r--  1 www-data www-data  8048 Jan 11 05:15 wp-mail.php
-rw-r--r--  1 www-data www-data 16255 Apr  6 18:23 wp-settings.php
-rw-r--r--  1 www-data www-data 29896 Oct 19  2016 wp-signup.php
-rw-r--r--  1 www-data www-data  4513 Oct 14  2016 wp-trackback.php
-rw-r--r--  1 www-data www-data  3065 Aug 31  2016 xmlrpc.php

I am trying to start the Wordpress container with a mounted Docker volume to be able to store the custom files persistently:

$ sudo docker run -p 80:80 --link some-mysql:mysql  -v /var/www:/var/www/html --name docker-wordpress -d wordpress

The problem is that even when exactly replicating the ownership and priviledges on local files in /var/www:

$ sudo chown -R www-data:www-data /var/www
$ sudo find /var/www/ -type d -exec chmod 755 {} \;
$ sudo find /var/www/ -type f -exec chmod 644 {} \;

I am still getting an error of this kind, when running Wordpress inside the container:

Could not create directory

How to set the privileges properly to make sure Wordpress is able to write into the mounted Docker volume?

like image 322
Peter G. Avatar asked May 29 '17 22:05

Peter G.


1 Answers

Looking at your error message i come to the conclusion that you are trying to install a plugin or update wordpress itself

This issue is slightly tricky to figure out.

executing chown -R www-data:www-data /var/www to set correct user:group permissions should technically solve it, however ..

On a new wordpress install the upload & plugins folder does not yet exist and therefore when installer trying to create a plugins/subfolder it will throw the error.

How to Fix Wordpress / Docker Plugin install Permission issue

Fixing this issue is however quite easy once grasping it.

Option A

in your .Docker file add following towards the very end but before any [CMD] command.

RUN mkdir /var/www/html/wp-content/plugins
RUN mkdir /var/www/html/wp-content/uploads
RUN chown -R www-data:www-data /var/www
RUN find /var/www/ -type d -exec chmod 0755 {} \;
RUN find /var/www/ -type f -exec chmod 644 {} \;

Option B

ssh in to your docker container
docker exec -it <container_name> /bin/bash

If you don't know the container name find it with
docker ps

Simply run same commands as in example above
$ mkdir /var/www/html/wp-content/plugins
$ mkdir /var/www/html/wp-content/uploads
$ chown -R www-data:www-data /var/www
$ find /var/www/ -type d -exec chmod 0755 {} \;
$ find /var/www/ -type f -exec chmod 644 {} \;

like image 164
Mathias Asberg Avatar answered Sep 19 '22 12:09

Mathias Asberg