duracellko / planningpoker4azure

Planning Poker 4 Azure
MIT License
64 stars 26 forks source link

How to set RepositoryFolder as environmental variable in docker-compose #134

Open T-6 opened 1 year ago

T-6 commented 1 year ago

Could you give me a hint how to do it correctly?

My docker-compose:

services: planningpoker: image: duracellko/planningpoker container_name: planningpoker network_mode: host environment: RepositoryFolder: "/planningpoker" user: "1002:100" restart: unless-stopped

Thanks a lot for your support!!!

duracellko commented 1 year ago

You have to specify full name of environment variable:

services:
  planningpoker:
    environment:
    - PlanningPoker__RepositoryForlder: /planningpoker

Explanation: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0#non-prefixed-environment-variables

Btw, when you specify repository like this, probably it would fail, because /planningpoker directory does not exist in the container. Also there is no need to store data in the container. The goal of repository was to store data outside of the container, so that when the container is restarted, the data are not lost. For that you would need to define a volume, map it in the container and use that for repository.

I found this that describes how to define volumes in docker compose: https://github.com/compose-spec/compose-spec/blob/master/spec.md

T-6 commented 1 year ago

Thanks for your answer. I use several container with bind mounts (volumes). In which file / folder are the data stored that should be stored between restarts? Then I can bind mount this folder to a folder on the host. Thanks

duracellko commented 1 year ago

It would be the same folder that you configure in the environment variable. For example:

services:
  planningpoker:
    environment:
    - PlanningPoker__RepositoryForlder: /planningpoker
    volumes:
    - /host/planningpoker/data:/planningpoker

/host/planningpoker/data should be directory. Then each team is stored as separate file there.

T-6 commented 1 year ago

This is my compose file:

services:
  planningpoker:
    image: duracellko/planningpoker
    container_name: planningpoker
    network_mode: host
    environment:
      PlanningPoker__RepositoryFolder: /planningpoker
    volumes:
       - /planningpoker:/planningboker
    restart: unless-stopped

When trying to change the deck to Fibonacci sequence, I get this:

fail: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[8]
      Failed to invoke hub method 'GetMessages'.
      System.UnauthorizedAccessException: Access to the path '/planningpoker' is denied.
       ---> System.IO.IOException: Permission denied
duracellko commented 1 year ago

The application inside docker runs under special app user. I assumer that the directory /planningpoker in the host was created by you and only you have access there. But not the app user. Simple solution is to make the directory public: chmod -R o=rw /planningpoker

Better option is to setup access explicitly to the app user. At first you have to find user-id. You would need run id command in the existing container: docker exec planningpoker id Then you can set the user to be the owner of the /planningpoker directory. chmod -R u=rw /planningpoker && chown -R {user id from the container} /planningpoker

T-6 commented 1 year ago

Usually I do not create directories which I use for bind mounts, but let docker-compose create them. As the container is running as root, the directory was created with root:root. The user app has id 1000. So I changed ownership of the directory to 1000:root and 1000:1000. But no success. I get still the same error message.

And it seems, I cannot run the container as another user like I do for others.

duracellko commented 1 year ago

I didn't even know, that docker-compose creates directories for volumes. Mu suggested next steps for investigation: