[docker] Dockerfile에서 PATH 환경 변수를 업데이트하는 방법은 무엇입니까?

소스에서 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



답변

다음과 같이 환경 교체 를 사용할 수 있습니다 Dockerfile.

ENV PATH="/opt/gtk/bin:${PATH}"


답변

Gunter가 게시 한 답변은 정확하지만 이미 게시 한 내용과 다르지 않습니다. 문제는 ENV지시문이 아니라 후속 지시 였습니다RUN export $PATH

ENVDockerfile에서 환경 변수를 선언하면 환경 변수를 내보낼 필요가 없습니다 .

RUN export ...선을 제거 하자마자 내 이미지가 성공적으로 작성되었습니다.


답변

PATH변수는 /etc/profile스크립트 로 설정 되므로 값을 무시할 수 있으므로 권장하지 않습니다 (깨끗한 Docker 이미지를 작성 / 배포하려는 경우) .

head /etc/profile:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

Dockerfile의 끝에 다음을 추가 할 수 있습니다.

RUN echo "export PATH=$PATH" > /etc/environment

따라서 모든 사용자에 대해 PATH가 설정됩니다.


답변