Search code examples
dockerdocker-composeodooscaffold

docker-compose odoo scaffold Permission Denied


I wrote this docker-compose.yaml file to generate aodoo instance:

version: "3.1"
services:
  web:
    image: odoo:16.0
    depends_on:
      - db
    ports:
      - "8069:8069"
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
      - ./log:/var/log/odoo
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=myodoo
  db:
    image: postgres:latest
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=myodoo
      - POSTGRES_USER=odoo
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - odoo-db-data:/var/lib/postgresql/data/pgdata

volumes:
  odoo-web-data:
  odoo-db-data:

Now i want to scaffold a new module so i got into bash using docker-compose exec web /bin/bash and did odoo scaffold test_module /mnt/extra-addons. I got this error

PermissionError: [Errno 13] Permission denied: '/mnt/extra-addons/test_module'

I have looked at many forums and other stack overflow questions that are simmilar but it does not seem to work. According to this github issue "The container does not have, and should not have, permissions to create /addons directory." But then how could i create a module?

The host machine is Windows11.


Solution

  • EDIT: the following is valide for a Linux host machine. For Windows something similar should be possible...

    One quick workaround would be to change the ownership of your local .addons directory to the user id running the odoo service in the container.

    $ docker run --entrypoint id odoo:16.0 
    uid=101(odoo) gid=101(odoo) groups=101(odoo)
    $ sudo chown -R 101:<your gid> ./addons
    $ sudo chmod -R g+rw ./addons
    $ sudo chmod g+s ./addons
    

    The later commands allows you to have write access to the files in your ./addons folder and to have the newly created files and folders belonging to your gid.

    More elaborate solution would be to create your own Docker image running Odoo with the uid of the user starting the Docker container. This approach has a number of advantages but need some more work to do the setup.