Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set ENV in Dockerfile with string interpolation
FROM ubuntu:12.04
# install essentials
RUN apt-get install -y -q git
# Install rbenv
RUN git clone /usr/local/rbenv
RUN echo '# rbenv setup' > /etc/profile.d/
RUN echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/
RUN echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/
RUN chmod +x /etc/profile.d/
# install ruby-build
RUN mkdir /usr/local/rbenv/plugins
RUN git clone /usr/local/rbenv/plugins/ruby-build
ENV RBENV_ROOT /usr/local/rbenv
ENV PATH "$RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
RUN echo $PATH
# does not work. PATH is set to
# $RBENV_ROOT/shims:$RBENV_ROOT/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Copy link

deepak commented Jul 5, 2013

cat Dockerfile.badruby | docker build -t deepak/badruby -


Step 11 : ENV RBENV_ROOT /usr/local/rbenv
---> Running in 57293936038d
---> f48435fd1f71
Step 12 : ENV PATH "$RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
---> Running in bac27d8ed4be
---> 0e088f91da43
Step 13 : RUN echo $PATH
---> Running in 80aefab5e4ea
---> 01727253a304

docker logs 80aefab5e4ea

Copy link

deepak commented Jul 5, 2013

docker run deepak/badruby /bin/sh -c "echo $PATH"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment