Reputation: 2389
I have a Dockerfile
recipe:
FROM ubuntu:18.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
SHELL ["/bin/bash", "-c"]
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 exec bash \
&& . /root/.bashrc \
&& conda init bash \
&& conda activate \
&& conda install -y pandas=1.3
When I use the command:
docker build -t myimage .
The image builds fine, however pandas
is not installed. How can I install packages in conda using a dockerfile ??
Upvotes: 6
Views: 15389
Reputation: 22691
As most as possible, if the software is available as "static" binary, use Docker multi-stages or "COPY from":
# Will copy from existing Docker image
COPY --from=continuumio/miniconda3:4.12.0 /opt/conda /opt/conda
ENV PATH=/opt/conda/bin:$PATH
# Usage examples
RUN set -ex && \
conda config --set always_yes yes --set changeps1 no && \
conda info -a && \
conda config --add channels conda-forge && \
conda install --quiet --freeze-installed -c main conda-pack
So you dont need to install curl / gzip / wget first in the image, code is cleaner & smaller end cached is better.
Upvotes: 7
Reputation: 2389
I managed to get done like that:
ARG UBUNTU_VER=18.04
ARG CONDA_VER=latest
ARG OS_TYPE=x86_64
ARG PY_VER=3.9
ARG PANDAS_VER=1.3
FROM ubuntu:${UBUNTU_VER}
# System packages
RUN apt-get update && apt-get install -yq curl wget jq vim
# Use the above args
ARG CONDA_VER
ARG OS_TYPE
# Install miniconda to /miniconda
RUN curl -LO "http://repo.continuum.io/miniconda/Miniconda3-${CONDA_VER}-Linux-${OS_TYPE}.sh"
RUN bash Miniconda3-${CONDA_VER}-Linux-${OS_TYPE}.sh -p /miniconda -b
RUN rm Miniconda3-${CONDA_VER}-Linux-${OS_TYPE}.sh
ENV PATH=/miniconda/bin:${PATH}
RUN conda update -y conda
RUN conda init
ARG PY_VER
ARG PANDAS_VER
# Install packages from conda
RUN conda install -c anaconda -y python=${PY_VER}
RUN conda install -c anaconda -y \
pandas=${PANDAS_VER}
Upvotes: 5