Search code examples
codenvy

How to set environment variables in Codenvy terminal


I'm using Codenvy to install golang and as part of the process I'm setting environment variables. I can set the environment variables just fine during the docker build process, but when I start the resulting Codenvy terminal the environment variables aren't set. How can I have the environment variables that are set in the dockerfile be present in the resulting terminal?

As an example if I take this dockerfile:

FROM codenvy/python34
ENV GOPATH /tmp/application/gopath
ENV PATH $GOPATH:$GOPATH/bin:$PATH
CMD echo $PATH && sleep 1h

...then in the docker build output I see

[STDOUT] /tmp/application/gopath:/tmp/application/gopath/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

...but when I open the terminal and look at the $PATH I see...

user@6ec34a856f91:~$ echo $PATH                                                                                                                                                                                         
/usr/local/bin:/usr/bin:/bin:/usr/games

Solution

  • The answer was sent to me from the Codenvy Google Group...you need to add lines to your /home/user/.bashrc file. This gets run when your terminal starts.

    RUN echo "export GOPATH=$GOPATH" >> /home/user/.bashrc
    RUN echo "export PATH=$GOPATH/bin:$PATH" >> /home/user/.bashrc