Secret_Wang
Secret_Wang

Reputation: 31

Why do I got "conda: command not found" when building a docker, while in base image the "conda" command works fine?

I am trying to build a docker from a base image, the Dockerfile is like this:

FROM my/base/image:latest
RUN conda install package-name
RUN rm -rf /tmp/*
CMD ["/bin/bash"]

and I got "conda: command not found". But if I directly run the base image as a container, the conda command works fine. Also, if I add RUN source ~/.bashrc in the Dockerfile, when building process run into this line, it will enter another terminal and will not response to any command. What‘s happening in this situation? I would be very grateful if anyone could give me any advice and suggestion. Thanks in advance.

Upvotes: 2

Views: 5697

Answers (1)

Romain
Romain

Reputation: 21958

~/.bashrc is sourced by interactive shells, it's the reason why it works when you use it from within the container. This is not the case for a Dockerfile during the build process.

In the conda docker image, the conda executable is simply added to the PATH.

ENV PATH /opt/conda/bin:$PATH

It's a simple solution. You can also call /opt/conda/bin/conda install ... (to adapt according to your conda installation) if you do not want to alter the PATH.

Alternative

If you want to have ~/.bashrc sourced you can use the SHELL instruction to override the default shell used for commands with a bash interactive shell (thanks to the i flag).

SHELL ["/bin/bash", "-i", "-c"] 
RUN conda install ...

However it seems to be a less conventional approach.

Upvotes: 2

Related Questions