0

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?

4
  • Use echo to write to the file Commented Apr 30, 2023 at 12:18
  • 1
    Also why not use a standard go image? Commented Apr 30, 2023 at 12:18
  • The settings are not saved in subsequent layers. Indeed, in this case, they are barely "saved" in the layer in which they are being executed. That RUN command invokes a shell which sources the .bash_profile and sets PATH in its environment, but that setting vanishes as soon as the shell that executed it exits. Commented Apr 30, 2023 at 12:38
  • I was using version 1.19.1 there was no image. Now Indeed I can use an image Commented Apr 30, 2023 at 12:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.