I am trying to modify my PATH variable in my Dockerfile. I am running source /root/.bash_profile
to change it. But PATH doesn't change. My Dockerfile:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=nonintercative
RUN apt-get update && apt-get install -y \
tar \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN wget -P /home "https://go.dev/dl/go1.20.src.tar.gz" && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf /home/"go1.20.src.tar.gz" && \
rm /home/"go1.20.src.tar.gz"
RUN echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile
#RUN /bin/bash -c 'source $HOME/.bash_profile'
RUN ["/bin/bash","-c","source $HOME/.bash_profile"]
When running the container I can see that the PATH hasn't been changed.
I've found that I can use the following command: ENV PATH="${PATH}:usr/local/go/bin:$HOME/go/bin"
I wonder why the first method does not work. Are the variables not saved between the different layers of the Docker image?