Allow WordPress write access to Docker mounted folder

I have a Docker setup that works well with Ubuntu, Nginx, PHP-FPM and MySQL.

WordPress can write to the uploads folder and I can edit templates online, but when I try to upgrade WordPress or plugins, it fails with:

Read More

Unpacking the update…

Could not create directory.: wordpress

Installation Failed

I have chmod 777 the entire WordPress folder, so I’m not sure if this is Docker or WordPress related. I have also checked various logs, but the only relevant line I found is this:

192.168.59.3 – – [01/Oct/2014:14:16:58 +0000] “POST /wp-admin/update-core.php?action=do-core-upgrade HTTP/1.1” 200 5576
“/wp-admin/update-core.php” “Mozilla/5.0
(Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/37.0.2062.124 Safari/537.36”

Here’s how I created the Docker environment:

brew install docker boot2docker
boot2docker init
# Allow VM access to our space
curl http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso > ~/.boot2docker/boot2docker.iso
VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
boot2docker up

Here’s how I start the container:

docker run -p 80:80 --name wp -d -v ~/wordpress:/mnt/www:rw wp

Here’s the Nginx configuration:

server {

    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /mnt/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server
    #
    location ~ .php$ {
    try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}

Related posts

Leave a Reply

2 comments

  1. I do not have access of your Dockerfile, but for permissions problems with docker and WordPress to install plugins, templates or create folders you can use the command COPY with chown parameter in Dockerfile. Like below:

    COPY [--chown=<user>:<group>] <src>... <dest>
    

    For example, in my code runnig wordpress, I use:

    COPY --chown=www-data:www-data ./app/ /var/www/html/ 
    

    But you need had the last version of Docker to use chown parameter. A lot of people get the unknown chown parameter, this occurs because of Docker version. So before use chown I indicate to update your Docker.

    Docker reference about COPY command: https://docs.docker.com/engine/reference/builder/#copy

    WordPress reference about permissions and www-data user: https://codex.wordpress.org/Changing_File_Permissions