Search code examples
pythonbashdockercondaminiconda

Dependencies not installed in conda environment within a Docker container


This exact Dockerfile was working 2 weeks ago and I can't figure out why it's not workingnow. Nothing has changed in the script.

Here's the Dockerfile

# v2023.6.6
# =================================
# Miniconda3
# =================================

FROM continuumio/miniconda3

ARG ENV_NAME

SHELL ["/bin/bash","-l", "-c"]

WORKDIR /root/

# Data
RUN mkdir -p /volumes/input
RUN mkdir -p /volumes/output
RUN mkdir -p /volumes/database


# Retrieve VEBA repository
RUN mkdir -p veba/
COPY ./install/ veba/install/
COPY ./src/ veba/src/
COPY ./VERSION veba/VERSION
COPY ./LICENSE veba/LICENSE

# Install Miniconda
RUN /opt/conda/bin/conda init bash && \
    /opt/conda/bin/conda config --add channels jolespin && \
    /opt/conda/bin/conda config --add channels bioconda && \
    /opt/conda/bin/conda config --add channels conda-forge && \
    /opt/conda/bin/conda update conda -y && \
    # /opt/conda/bin/conda install -c conda-forge mamba -y && \ # Mamba adds about 450 MB to image
    # /opt/conda/bin/mamba init bash && \
    /opt/conda/bin/conda clean -afy

# =================================

# Add conda bin to path
ENV PATH /opt/conda/bin:$PATH

# Create environment
RUN conda env create -n ${ENV_NAME} -f veba/install/environments/${ENV_NAME}.yml
# RUN mamba env create -n ${ENV_NAME} -f veba/install/environments/${ENV_NAME}.yml

# Add environment scripts to environment bin
RUN /bin/bash veba/install/update_environment_scripts.sh veba/

# # Add contents to path
# ENV PATH /opt/conda/envs/${ENV_NAME}/bin:$PATH

# Set up environment
RUN echo "conda activate ${ENV_NAME}" >> ~/.bashrc

# Set entrypoint to bash
ENTRYPOINT ["bash", "-l", "-c"]

Here's my environment.yml file

Last time I built this image, my dockerfile created exactly as expected. Now it's not even installing pandas. I tried launching a docker container and manually installing. No errors were thrown but it didn't install any of the dependencies.

This is from within the Docker container in an interactive session:

(base) root@c3be34361e98:~# conda env create -n test_env -f veba/install/environments/VEBA-preprocess_env.yml
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 23.5.0
  latest version: 23.7.2

Please update conda by running

    $ conda update -n base -c conda-forge conda

Or to minimize the number of packages updated during conda update use

     conda install conda=23.7.2



Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate test_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) root@c3be34361e98:~# conda activate test_env
(test_env) root@c3be34361e98:~# conda env list
# conda environments:
#
base                     /opt/conda
test_env              *  /opt/conda/envs/test_env

(test_env) root@c3be34361e98:~# conda list
# packages in environment at /opt/conda/envs/test_env:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
dependencies              7.7.0              pyhd8ed1ab_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.1.0               he5830b7_0    conda-forge
libgomp                   13.1.0               he5830b7_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libsqlite                 3.42.0               h2797004_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
ncurses                   6.4                  hcb278e6_0    conda-forge
openssl                   3.1.1                hd590300_1    conda-forge
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
python                    3.11.4          hab00c5b_0_cpython    conda-forge
readline                  8.2                  h8228510_1    conda-forge
setuptools                68.0.0             pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
wheel                     0.41.0             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge

My question:

Why is my conda not installing the dependencies within the Docker container?


Solution

  • The environment part works fine with the latest Micromamba image:

    FROM mambaorg/micromamba:1.4.9
    COPY --chown=$MAMBA_USER:$MAMBA_USER VEBA-preprocess_env.yml /tmp/env.yml
    
    RUN micromamba install -yn base -f /tmp/env.yml && \
        micromamba clean -qafy
    

    Consider starting over from this, since it implements some better practices and vastly simplifies the boiler plate. Note rather than using a second environment, we simply just put everything in base, and with Micromamba, there isn't anything else in base but your environment specification. See the micromamba-docker documentation.