0
Ubuntu 20.04.4 LTS

Docker version 20.10.12

docker-compose version 1.29.2

This is the permission for WordPress directory

ls -l files/
total 212
-rw-r--r--  1 ubuntu ubuntu   405 Feb 24 13:33 index.php
-rw-r--r--  1 ubuntu ubuntu 19915 Feb 24 13:33 license.txt
-rw-r--r--  1 ubuntu ubuntu  7437 Feb 24 13:33 readme.html
-rw-r--r--  1 ubuntu ubuntu  7165 Feb 24 13:33 wp-activate.php
drwxr-xr-x  9 ubuntu ubuntu  4096 Feb 24 13:34 wp-admin
-rw-r--r--  1 ubuntu ubuntu   351 Feb 24 13:33 wp-blog-header.php
-rw-r--r--  1 ubuntu ubuntu  2338 Feb 24 13:33 wp-comments-post.php
-rw-r--r--  1 ubuntu ubuntu  3001 Feb 24 13:33 wp-config-sample.php
drwxr-xr-x  4 ubuntu ubuntu  4096 Feb 24 13:33 wp-content
-rw-r--r--  1 ubuntu ubuntu  3939 Feb 24 13:33 wp-cron.php
drwxr-xr-x 26 ubuntu ubuntu 12288 Feb 24 13:34 wp-includes
-rw-r--r--  1 ubuntu ubuntu  2496 Feb 24 13:33 wp-links-opml.php
-rw-r--r--  1 ubuntu ubuntu  3900 Feb 24 13:33 wp-load.php
-rw-r--r--  1 ubuntu ubuntu 47916 Feb 24 13:33 wp-login.php
-rw-r--r--  1 ubuntu ubuntu  8582 Feb 24 13:33 wp-mail.php
-rw-r--r--  1 ubuntu ubuntu 23025 Feb 24 13:33 wp-settings.php
-rw-r--r--  1 ubuntu ubuntu 31959 Feb 24 13:33 wp-signup.php
-rw-r--r--  1 ubuntu ubuntu  4747 Feb 24 13:33 wp-trackback.php
-rw-r--r--  1 ubuntu ubuntu  3236 Feb 24 13:33 xmlrpc.php

This is my docker-compose.yml file

version: '3.9'

services: 
  nginx: 
    image: nginx:stable-alpine
    ports: 
      - 80:80
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./files:/var/www/html
  mysql: 
    image: mysql:latest
    environment: 
      MYSQL_DATABASE: wp
      MYSQL_USER: wp
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
  php: 
    build:
      context: .
      dockerfile: php.dockerfile
    volumes:
      - ./files:/var/www/html

This is the php.docker file

FROM php:7.4-fpm-alpine

RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql

When I run the WordPress installation, I get error

Unable to write to wp-config.php file

It seems like PHP container didn't have the correct permissions to write to the filesystem that is on my local volume ./files.

I searched a lot and I think I am having the same problem as this one Laravel and Docker permission issue - can't save files but for WordPress.

According to above solution, I tried to add user: "1000:1000" into my docker-compose.yml but it throws following error due to docker-compose version I think

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.php.build contains unsupported option: 'user'

What should be the workaround here to resolve this permission issue

Farmi
  • 133
  • 1
  • 8

0 Answers0