1

I have a line in a dockerfile to set the container's environment variable based on the output of an npm script:

ENV BUILD_VERSION=$(npm pkg get version | sed 's/"//g')

running npm pkg get version | sed 's/"//g' in my terminal outputs:

❯ npm pkg get version | sed 's/"//g' 
4.12.3

But, in the dockerfile I get this error when building:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: Syntax error - can't find = in "pkg". Must be of the form: name=value

d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • `ENV` doesn't support interpolating command output as far as I know. This can be solved using a build argument, though. So where ever you are running `docker build` you can include the `--build-arg` option and interpolate your build version into that, instead. – ant Oct 15 '21 at 15:28
  • Examples [here](https://docs.docker.com/engine/reference/builder/#arg) – ant Oct 15 '21 at 15:29
  • Thanks @ant i was hoping to have this automated in the dockerfile as opposed to having to enter yet another build command (if possible!) – d-_-b Oct 15 '21 at 15:51

0 Answers0