-1

I am trying to set an arg for docker compose using an output of linux command as my example:

args:
     ID_GITLAB: $(id -u $USER)

but when I run my compose I get following error:

ERROR: Invalid interpolation format for "build" option in service "gpc-fontes-ci": "$(id -u $USER)"
kenorb
  • 155,785
  • 88
  • 678
  • 743
Rogger Fernandes
  • 805
  • 4
  • 14
  • 28
  • Possible duplicate of [How to pass arguments within docker-compose?](https://stackoverflow.com/questions/34322631/how-to-pass-arguments-within-docker-compose) – Mike Doe Feb 09 '18 at 11:59
  • I don't think you can invoke shell functions within Compose. Where did you learn that you could? – OneCricketeer Feb 09 '18 at 13:37
  • Possible duplicate of [How can I escape a $ dollar sign in a docker compose file?](https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-docker-compose-file) – kenorb Feb 16 '19 at 13:45

2 Answers2

2

Just do

USER_ID=$(id -u $USER) docker-compose

With the Compose file using a regular variable

args:
     ID_GITLAB: $USER_ID
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
-1

You need to escape $ character with another $, e.g.

args:
     ID_GITLAB: $$(id -u $USER)

It's the same rule for command.

See: Variable substitution.

You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don’t want processed by Compose.

For example:

web:
  build: .
  command: "$$VAR_NOT_INTERPOLATED_BY_COMPOSE"
kenorb
  • 155,785
  • 88
  • 678
  • 743