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.

  • Can I control the owner of a bind-mounted volume in a docker image?
  • What is meant by this weird docker command?
  • Bluemix - IBM Containers problems for US South?
  • How do you iteratively develop with docker?
  • Symfony2 app always has a 3 second wait between kernel.request and kernel.controller
  • CI: Should I run tests directly or through Docker container?
  • 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 :

        args:
          - 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?

  • Connection refused on docker container
  • Running Remote Bamboo Agents on Demand Using Docker
  • How can I debug my docker container with docker-machine and PHPStorm
  • Docker best practices: single process for a container
  • ps command cannot connect to the docker daemon even after adding user to docker group [duplicate]
  • reading IP address of a host machine inside a docker container
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.