Install homebrew using Dockerfile

I am trying to install homebrew using Dockerfile but I am unable to do so. I have the following statement (based on the alternative installation steps on https://docs.brew.sh/Homebrew-on-Linux):

RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew 
&& mkdir ~/.linuxbrew/bin 
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin 
&& eval $(~/.linuxbrew/bin/brew shellenv)
RUN brew --version

The last line throws an error saying “brew command not found”.

I am able to run the same exact steps using ENTRYPOINT and specifying a bash file.

Any help on this will be appreciated.

Source: StackOverflow