Permission denied: ‘/home/frappe/frappe-bench/logs/bench.log’ in 'docker' when use external volume

I want persistent data via docker-compose. So I change the original pwd.yml as follow:

version: "3"

services:
  backend:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  configurator:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: none
    entrypoint:
      - bash
      - -c
    command:
      - >
        bench set-config -g db_host $$DB_HOST;
        bench set-config -gp db_port $$DB_PORT;
        bench set-config -g redis_cache "redis://$$REDIS_CACHE";
        bench set-config -g redis_queue "redis://$$REDIS_QUEUE";
        bench set-config -g redis_socketio "redis://$$REDIS_SOCKETIO";
        bench set-config -gp socketio_port $$SOCKETIO_PORT;
    environment:
      DB_HOST: db
      DB_PORT: "3306"
      REDIS_CACHE: redis-cache:6379
      REDIS_QUEUE: redis-queue:6379
      REDIS_SOCKETIO: redis-socketio:6379
      SOCKETIO_PORT: "9000"
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  db:
    image: mariadb:10.6
    healthcheck:
      test: mysqladmin ping -h localhost --password=m823ah321bb
      interval: 1s
      retries: 15
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --skip-character-set-client-handshake
      - --skip-innodb-read-only-compressed # Temporary fix for MariaDB 10.6
    environment:
      MYSQL_ROOT_PASSWORD: m823ah321bb
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/db-data:/var/lib/mysql

  frontend:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - nginx-entrypoint.sh
    environment:
      BACKEND: backend:8000
      FRAPPE_SITE_NAME_HEADER: 101.33.233.228
      SOCKETIO: websocket:9000
      UPSTREAM_REAL_IP_ADDRESS: 
      UPSTREAM_REAL_IP_HEADER: 
      UPSTREAM_REAL_IP_RECURSIVE: "off"
      PROXY_READ_TIMOUT: 120
      CLIENT_MAX_BODY_SIZE: 50m
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs
    ports:
      - "8600:8080"

  queue-default:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - bench
      - worker
      - --queue
      - default
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  queue-long:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - bench
      - worker
      - --queue
      - long
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  queue-short:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - bench
      - worker
      - --queue
      - short
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  redis-queue:
    image: redis:6.2-alpine
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/redis-queue-data:/data

  redis-cache:
    image: redis:6.2-alpine
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/redis-cache-data:/data

  redis-socketio:
    image: redis:6.2-alpine
    deploy:
      restart_policy:
        condition: on-failure
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/redis-socketio-data:/data

  scheduler:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - bench
      - schedule
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

  websocket:
    image: frappe/erpnext:v14.13.0
    deploy:
      restart_policy:
        condition: on-failure
    command:
      - node
      - /home/frappe/frappe-bench/apps/frappe/socketio.js
    volumes:
      - /home/new/apps/erpnextfinal/erp-data/sites:/home/frappe/frappe-bench/sites
      - /home/new/apps/erpnextfinal/erp-data/logs:/home/frappe/frappe-bench/logs

It start correctly. However it display the following error when I run the command to create the site:

docker-compose --project-name erpa exec backend \
	       bench new-site example.top \
	       --mariadb-root-password xxh321bb \
	       --admin-password adnux \
	       --no-mariadb-socket \
	       --install-app erpnext 

It shows:

Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/site-packages/bench/cli.py", line 76, in cli
    logger = setup_logging()
  File "/usr/local/lib/python3.10/site-packages/bench/utils/__init__.py", line 185, in setup_logging
    hdlr = logging.FileHandler(log_file)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1169, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1201, in _open
    return open_func(self.baseFilename, self.mode,
PermissionError: [Errno 13] Permission denied: '/home/frappe/frappe-bench/logs/bench.log'

How to resolve the problem under the docker environment?

Best regards.

My System is Ubuntu 20.04 LTS
My docker version:

Docker version 20.10.22, build 3a2c30b

Docker Compose version v2.13.0

make sure the directory is owned by uid:gid frappe:frappe 1000:1000

read this Container Basics

it explains exact error

I try:

export prjname=erpa

sudo docker-compose --project-name $prjname exec backend \
     chown -R frappe:frappe /home/frappe/frappe-bench/logs

Also:

sudo docker-compose --project-name $prjname exec backend \
     chown -R frappe:frappe /home/frappe/frappe-bench
sudo docker-compose --project-name $prjname exec backend \
     chown -R 1000:1000 /home/frappe/frappe-bench

They all show:

chown: changing ownership of '/home/frappe/frappe-bench/logs': Operation not permitted

I think it has no user named frappe in my host machine.
Thus I generate the user frappe by using sudo useradd frappe in my host machine and retrying the previous command.
The error is still the same.

I also try to change the ownership outside the docker by sudo chown -R frappe:frappe ./erp-data, it still has the error as the first floor.

--user=root or from host machine

here 1000:1000

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.