Can't add write permission to docker volume in docker-compose

Bar Bokovza picture Bar Bokovza · Jun 14, 2018 · Viewed 8.2k times · Source

Issue

My main goal is to create a wordpress container on my linux machine for development on that container.

Therefore, I'm creating new volumes for the plugins and themes folders and even add read & write permissions, with the :rw option.

However, when I'm trying to create a new directory or file in those "volumes", I get an error message (especially in VS Code), that tells that I don't have the permission to add these volumes.

Moreover, the permissions based on the ll command shows that the owner is the only one with the w permissions. It means that I cannot use the group www-data and add it to my user in order to edit those volumes.

When I'm trying to run chmod 766 themes plugins, the volumes are not bind anymore, so this solution doesn't work.

I've searched the whole web (including stack overflow), but none of the answers didn't work for me, so I'm lost :(

Here are some details that can help you with finding solution, including the docker-compose.yml file.

Details

Error on VS Code when trying to add a directory named hello

A system error occurred (EACCES: permission denied, mkdir '~/Workspace/WordpressProject/themes/hello')

Run mkdir hello in terminal, returns this error

mkdir: cannot create directory ‘hello’: Permission denied

ll command result for volumes

drwxr-xr-x 2 www-data www-data 4096 Jun 14 23:54 plugins/
drwxr-xr-x 5 www-data www-data 4096 May 17 22:00 themes/

docker-compose.yml

version: '3'
services:
  wordpress:
    image: wordpress
    links:
      - mariadb:mysql
    environment:
      - WORDPRESS_DB_PASSWORD=${Database Name}
    ports:
      - "127.0.0.101:80:80"
    hostname: ${Wordpress Host}
    volumes:
      - ./plugins:/var/www/html/wp-content/plugins:rw
      - ./themes:/var/www/html/wp-content/themes:rw
    restart: always
  mariadb:
    image: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=${Password}
      - MYSQL_DATABASE=${Database Name}
    volumes:
      - ./database:/var/lib/mysql
    restart: always

Versions

  • OS: Ubuntu 18.04 LTS
  • Docker: v18.05.0-ce, API v1.37
  • Editor (Visual Studio Code): v1.23.1

Answer

user9008857 picture user9008857 · Jun 14, 2018

Please in VS terminal execute:

sudo chown -R $USER <directory_project>