Search code examples
dockershdockerfile

Iterate in RUN command in Dockerfile


I have a line that looks something like:

RUN for i in `x y z`; do echo "$i"; done

...with the intention of printing each of the three items

But it raises /bin/sh: 1: x: not found

Any idea what I'm doing wrong?


Solution

  • It looks like you're using backticks. What's in backticks gets executed and the text in the backticks gets replaced by what's returned by the results.

    Try using single quotes or double quotes instead of backticks.

    Try getting rid of the backticks like so:

    RUN for i in x y z; do echo "$i"; done