Open Kanthavel-Spindox opened 2 months ago
Following the tutorial, when a new app is created, all app files are created under owner root and group root.
root
This is due to the default execution of docker compose run, which runs as root.
docker compose run
Considering that the app init command generates a template, it is quite annoying not to be able to modify it without sudo rights.
app init
Modify all relevant services in docker-compose.yml adding a user parameter. My best attempt is something like this
docker-compose.yml
user
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"
DOCKER_USER="$(id -u):$(id -g)" docker compose up -d
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/
Specify the user ID in docker compose run: alias "sermas-cli=docker compose run --user $(id -u):$(id -g) --rm -it cli"
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.
chown
Another possible approach is descibed here https://stackoverflow.com/a/75508108/833499
Following the tutorial, when a new app is created, all app files are created under owner
root
and grouproot
.This is due to the default execution of
docker compose run
, which runs asroot
.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 auser
parameter. My best attempt is something like thisAnd then running
DOCKER_USER="$(id -u):$(id -g)" docker compose up -d
and the aliasalias "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.