sermas-eu / sermas-toolkit-api

SERMAS Toolkit API
https://sermas-eu.github.io
Apache License 2.0
0 stars 0 forks source link

Linux - New App files created under root #3

Open Kanthavel-Spindox opened 1 month ago

Kanthavel-Spindox commented 1 month ago

Following the tutorial, when a new app is created, all app files are created under owner root and group root.

This is due to the default execution of docker compose run, which runs as root.

Considering that the app init command generates a template, it is quite annoying not to be able to modify it without sudo rights.

Partial workaround 1

Modify all relevant services in docker-compose.yml adding a user parameter. My best attempt is something like this

  cli:
    image: ghcr.io/sermas-eu/cli:dev
    networks:
      - sermas_dev
    environment:
      - CONFIG_DIR=/data
    volumes:
      - ./data/cli:/data
      - ./apps:/apps
    user: "${DOCKER_USER}"

And then running DOCKER_USER="$(id -u):$(id -g)" docker compose up -d and the alias alias "sermas-cli=DOCKER_USER=\"$(id -u):$(id -g)\" docker compose run --rm -it cli"

With this solution I can NOT login, but that may be caused by some other issue.

Sources: https://stackoverflow.com/questions/48727548/how-to-configure-docker-compose-yml-to-up-a-container-as-root https://blog.giovannidemizio.eu/2021/05/24/how-to-set-user-and-group-in-docker-compose/

Partial workaround 2

Specify the user ID in docker compose run: alias "sermas-cli=docker compose run --user $(id -u):$(id -g) --rm -it cli"

This solution still fails to save the credentials, since the relevant JSON file is owned by root. A manual chown may be needed. image

Kanthavel-Spindox commented 3 weeks ago

Another possible approach is descibed here https://stackoverflow.com/a/75508108/833499