Using command output as environment variable value?

I’d like to replicate a user’s GID and UID to create a new user in my image using these values in order to fix permission problems with a volume.

I already found this answer that explain how to do.

  • How to add tags to docker images made using autobuild
  • Docker - nginx with custom config
  • How can I modify Docker's internal IP on a Mac?
  • Conditional Block in Docker
  • Trouble setting up LDAPS for login in Sonarqube Docker container
  • CHMOD in dockerfile for python
  • But I’d also like to do it dynamically in my docker-compose.yml file.

    To achieve this I’d like to dynamically retrieve these values by using a command output. But I don’t know if it’s possible with docker compose files.

    I tried this :

          - GIT_UID="$(grep git /etc/passwd | cut -d : -f 3)"
          - GIT_GID="$(grep git /etc/passwd | cut -d : -f 4)"

    and tried some variants.

    But so far I didn’t succeed to make it work, I get this error :

    ERROR: The Compose file './docker-compose.yml' is invalid because:
    services.gogs.environment contains {"GIT_UID=\"$(grep git /etc/passwd | cut -d": "-f 3)\""}, which is an invalid type, it should be a string

    Is it possible to use a command output as an environment variable value with docker-compose files and if yes how should I do?

  • Is it “safe” to commit a running container in docker?
  • add ca certificate to build container such that git fetch can use it?
  • What's the difference between “docker start” and “docker restart”?
  • Is NoRestart policy supported for Kubernetes pods?
  • How are docker image names parsed?
  • Express does not run on docker, but on localhost
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.