In the Docker file, how to update the PATH environment variable?

I have a docker file that downloads and builds GTK from source, but the following line does not update my image environment variable:

RUN PATH="/opt/gtk/bin:$PATH" RUN export PATH 

I read that I have to use ENV to set environment values, but the following instruction does not work either:

ENV PATH /opt/gtk/bin:$PATH

This is my entire Docker file:

 FROM ubuntu RUN apt-get update RUN apt-get install -y golang gcc make wget git libxml2-utils libwebkit2gtk-3.0-dev libcairo2 libcairo2-dev libcairo-gobject2 shared-mime-info libgdk-pixbuf2.0-* libglib2-* libatk1.0-* libpango1.0-* xserver-xorg xvfb # Downloading GTKcd RUN wget http://ftp.gnome.org/pub/gnome/sources/gtk+/3.12/gtk+-3.12.2.tar.xz RUN tar xf gtk+-3.12.2.tar.xz RUN cd gtk+-3.12.2 # Setting environment variables before running configure RUN CPPFLAGS="-I/opt/gtk/include" RUN LDFLAGS="-L/opt/gtk/lib" RUN PKG_CONFIG_PATH="/opt/gtk/lib/pkgconfig" RUN export CPPFLAGS LDFLAGS PKG_CONFIG_PATH RUN ./configure --prefix=/opt/gtk RUN make RUN make install # running ldconfig after make install so that the newly installed libraries are found. RUN ldconfig # Setting the LD_LIBRARY_PATH environment variable so the systems dynamic linker can find the newly installed libraries. RUN LD_LIBRARY_PATH="/opt/gtk/lib" # Updating PATH environment program so that utility binaries installed by the various libraries will be found. RUN PATH="/opt/gtk/bin:$PATH" RUN export LD_LIBRARY_PATH PATH # Collecting garbage RUN rm -rf gtk+-3.12.2.tar.xz # creating go code root RUN mkdir gocode RUN mkdir gocode/src RUN mkdir gocode/bin RUN mkdir gocode/pkg # Setting the GOROOT and GOPATH enviornment variables, any commands created are automatically added to PATH RUN GOROOT=/usr/lib/go RUN GOPATH=/root/gocode RUN PATH=$GOPATH/bin:$PATH RUN export GOROOT GOPATH PATH 
+75
docker dockerhub
Nov 23 '14 at 19:58
source share
2 answers

Although the answer Gunther posted was right, it is no different from what I already posted. The problem was not the ENV directive, but the subsequent RUN export $PATH statement

There is no need to export environment variables once you have declared them via ENV in your Docker file.

Once the RUN export ... lines were deleted, my image was successfully executed

+26
Nov 24 '14 at 1:18
source share

You can use Environment Replacement in your Dockerfile as follows:

 ENV PATH="/opt/gtk/bin:${PATH}" 
+105
Aug 03 '16 at 11:39 on
source share



All Articles