我有一个从源代码下载和构建GTK的dockerfile,但是下面的代码行没有更新我的映像的环境变量:
RUN PATH="/opt/gtk/bin:$PATH"
RUN export PATH
我读到应该使用ENV来设置环境值,但下面的指令似乎也不起作用:ENV PATH /opt/gtk/bin:$PATH
这是我的整个Dockerfile:
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
4条答案
按热度按时间5gfr0r5j1#
您可以在
Dockerfile
中使用“环境替换”,如下所示:yhqotfr82#
虽然Gunter发布的答案是正确的,但与我已经发布的答案没有什么不同,问题不在于
ENV
指令,而在于后续的RUN export $PATH
指令一旦您在Dockerfile中通过
ENV
声明了环境变量,就不需要导出它们。删除
RUN export ...
行后,我的映像就成功构建了pdkcd3nj3#
[* 我在回答所选答案时提到了这一点,但有人建议将其作为一个单独的答案更加突出 *]
应当指出的是,
可能与
前者,用花括号括起来,可能会提供主机的PATH。文档没有建议这种情况,但我观察到它是这样的。这很容易检查,只需执行
RUN echo $PATH
并将其与RUN echo ${PATH}
进行比较vbopmzt14#
不建议这样做(如果您想创建/分发干净的Docker映像),因为
PATH
变量是由/etc/profile
脚本设置的,该值可以被覆盖。head /etc/profile
:在Dockerfile的末尾,您可以添加:
所以PATH是为所有用户设置的。