I want to be able to assign an command's output to an ARG variable while inside a Dockerfile. For example:
ARG myvar=$(echo 'hello')
However, this gives me syntax error
ERROR: Dockerfile parse error line 68: ARG requires exactly one argument
Is there a way to work around this?
Although not a direct answer to the question, the way I solved this problem was by creating a bash script that is responsible for starting the Dockerfile build. The script runs the command I need and then passes it as an argument to the Dockerfile. Example:
#!/usr/bin/env bash
MY_VAR=$(echo 'hello')
docker build --build-arg MY_VAR=${MY_VAR} -t myapp .
And then the Dockerfile gets it:
ARG MY_VAR
# MY_VAR now equals 'hello'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With