dockerminiconda

conda not initializing in docker


I'm building a docker container for an LLM:

https://github.com/bytedance/LatentSync/tree/main

And the setup script provided in that repo uses conda. Installing miniconda hasn't been an issue, however trying to initialize it has proven difficult. This is my Dockerfile:

FROM ubuntu:latest
ARG PYTHON_VERSION=3.10.13

SHELL ["/bin/bash", "-c"]
RUN apt-get update && apt-get install -y git
# Install base utilities
RUN apt-get update \
    && apt-get install -y build-essential \
    && apt-get install -y wget \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get -y install sudo

# Install Python
#RUN apt-get install -y python3.6 \
    #&& ln -s /usr/bin/python3.6 /usr/bin/python3

# Install miniconda
ENV CONDA_DIR=/opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
    /bin/bash ~/miniconda.sh -b -p /opt/conda

# Put conda in path so we can use conda activate
ENV PATH=$CONDA_DIR/bin:$PATH

RUN pip install --upgrade pip
RUN pip install -U "huggingface_hub[cli]"

WORKDIR /app
RUN git clone https://github.com/bytedance/LatentSync.git
WORKDIR "LatentSync"
RUN conda tos accept --override-channels --channel defaults
RUN conda init
RUN source setup_env.sh

I see an error in the logs:

#
# To activate this environment, use
#
# $ conda activate latentsync
#
# To deactivate an active environment, use
#
# $ conda deactivate
CondaError: Run 'conda init' before 'conda activate'

However, I do run that conda init before running the setup, what am I missing here?


Solution

  • Every RUN <command> in Dockerfile (so called shell form) is executed as launching /bin/sh -c <command>, so your environment is not saved between RUN commands. Instead, you should pack the last 3 commands in single instruction:
    RUN conda tos accept --override-channels --channel defaults && conda init && . setup_env.sh