How to install packages with miniconda in Dockerfile?

Question:

I have a simple Dockerfile:

FROM ubuntu:18.04

RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

RUN wget 
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
    && mkdir /root/.conda 
    && bash Miniconda3-latest-Linux-x86_64.sh -b 
    && rm -f Miniconda3-latest-Linux-x86_64.sh 
    && echo PATH="/root/miniconda3/bin":$PATH >> .bashrc 
    && exec bash 
    && conda --version

RUN conda --version

And it cannot be built. At the very last step I get /bin/sh: 1: conda: not found….
The first appearance of conda --version did not raise an error which makes me wonder is that an PATH problem?
I would like to have another RUN entry in this Dockerfile in which I would install packages with conda install ...
At the end I want to have CMD ["bash", "test.py"] entry so that when in do docker run this image it automatically runs a simple python script that imports all the libraries installed with conda. Maybe also a CMD ["bash", "test.sh"] script that would test if conda and python interpreter are indeed installed.

This is a simplified example, there will be a lot of software so I do not want to change the base image.

Asked By: maciek

||

Answers:

This will work using ARG and ENV:

FROM ubuntu:18.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

RUN wget 
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
    && mkdir /root/.conda 
    && bash Miniconda3-latest-Linux-x86_64.sh -b 
    && rm -f Miniconda3-latest-Linux-x86_64.sh 
RUN conda --version
Answered By: LinPy

@soren — you must run $CONDA_BIN/conda init. restart a new shell. then conda activate should work. conda init updates your shall login profiles to setup conda upon login (or sourcing, say .bashrc)

Answered By: iamh2o

I try to build and publish a package into GitHub Container Registry. I install miniconda in DockerFile and it works fine in other environments but GitHub Action gives me the following error in the build&push step. Any ideas on how I can fix this error?

ERROR: failed to solve: process "/bin/sh -c wget thttps://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh t&& mkdir /root/.conda t&& bash Miniconda3-latest-Linux-x86_64.sh -b t&& rm -f Miniconda3-latest-Linux-x86_64.sh t&& echo PATH="/root/miniconda3/bin":$PATH >> .bashrc t&& exec bash t&& conda --version t&& conda install jupyter" did not complete successfully: exit code: 127
Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c wget thttps://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh t&& mkdir /root/.conda t&& bash Miniconda3-latest-Linux-x86_64.sh -b t&& rm -f Miniconda3-latest-Linux-x86_64.sh t&& echo PATH="/root/miniconda3/bin":$PATH >> .bashrc t&& exec bash t&& conda --version t&& conda install jupyter" did not complete successfully: exit code: 127
Answered By: Özer Özdal