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.

  • Ansible, how to add user to group only if user exists
  • Kong in Docker : Configuring API endpoints without curl
  • How can I run docker-compose up as shell script by Jenkins
  • Get status of an ongoing docker image pull
  • Cannot install docker on OS X Version 10.9.5
  • Magento devbox not install
  • 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?

  • How to get a Docker container's IP address from the host?
  • Want to ssh into a running docker container running inside CentOs Image
  • Ansible docker_container 'no Host in request URL', docker pull works correctly
  • All containers inside a digital ocean droplet stop
  • Docker do not work from build remotely at Jenkins slave. What' the reason?
  • how to add localhost to docker machine
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.