'In Docker, how do I capture the output of a command for use in other parts of my Dockerfile?
I’m using Docker v20.10.12. I have this in my Dockerfile
ENV RBENV_VERSION 3.0.2
RUN eval "$(rbenv init -)"; rbenv install $RBENV_VERSION \
&& eval "$(rbenv init -)"; rbenv global $RBENV_VERSION \
&& eval "$(rbenv init -)"; gem update --system \
&& eval "$(rbenv init -)"; gem install bundler -f \
&& rm -rf /tmp/*
I would like to set the RBENV_VERSION to be the output of a command, “$(cat .ruby-version)” for use with my RUN command, but evidently it isn’t possible to set a Docker ENV var in this way. Is there another way to capture the output of that command and use that in my Dockerfile, if not in just that one RUN command?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
