I have a Dockerfile in which I am trying to install and use asdf to manage Python package versions. A snippet of my Dockerfile appears below.
SHELL ["/bin/bash", "-c"]
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
RUN chmod +x ~/.asdf/asdf.sh ~/.asdf/completions/asdf.bash
RUN echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc
RUN echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc
ENV PATH="$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
ENV PATH="$HOME/.asdf:$PATH"
RUN echo -e '\nsource $HOME/.asdf/asdf.sh' >> ~/.bashrc
RUN source ~/.bashrc
RUN bash -c 'echo -e which asdf'
RUN asdf plugin-add python
That last line is the offending line. When I try to build this Docker image, I get the following.
=> ERROR [17/19] RUN asdf plugin-add python 0.3s
------
> [17/19] RUN asdf plugin-add python:
#21 0.292 /bin/bash: asdf: command not found
------
executor failed running [/bin/bash -c asdf plugin-add python]: exit code: 127
However, if I remove that line, I'm able to run a container and then just immediately run asdf successfully.
docker run -it <image ID>
root:# asdf plugin-add python
initializing plugin repository...Cloning into '/root/.asdf/repository'...
<etc>
Why doesn't this work when I try to run it through the Dockerfile?
python
images? Often version managers likeasdf
don't work well in Docker, since shell dotfiles usually aren't used at all (you are not running an "interactive" or "login" shell). – Sooth