ReproNim / neurodocker

Generate custom Docker and Singularity images, and minimize existing containers
https://www.repronim.org/neurodocker/
Apache License 2.0
326 stars 97 forks source link

activating conda to use datalad in a neurodocker recipe #532

Open Remi-Gau opened 1 year ago

Remi-Gau commented 1 year ago

I need to use datalad installed via conda to get some data into a container.

Installing datalad itself works but then running it to get the data requires to first activate conda environment.

The doc is not very clear on how one is supposed to do this.

Current recipe is this

  docker run --rm repronim/neurodocker:0.9.5 generate docker \
             --base-image bids/base_validator \
             --yes \
             --pkg-manager apt \
             --install git num-utils gcc g++ curl build-essential nano\
             --miniconda \
                version=latest \
                env_name=bidsonym \
                env_exists=false\
                conda_install="python=3.10 numpy nipype nibabel pandas" \
                pip_install="deepdefacer tensorflow scikit-image pydeface==2.0.2 nobrainer==0.4.0 quickshear==1.2.0 datalad datalad-osf" \
             --fsl version=6.0.6.4 method=binaries \
             --run-bash "mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && conda activate bidsonym && datalad datalad clone https://github.com/neuronets/trained-models && cd trained-models && git-annex enableremote osf-storage && datalad get -s osf-storage ."
             --run-bash "git clone https://github.com/mih/mridefacer" \
             --env MRIDEFACER_DATA_DIR=/mridefacer/data \
             --run-bash "mkdir /home/mri-deface-detector && cd /home/mri-deface-detector && npm install sharp --unsafe-perm && npm install -g mri-deface-detector --unsafe-perm && cd ~" \
             --run-bash "git clone https://github.com/miykael/gif_your_nifti && cd gif_your_nifti && source activate bidsonym && python setup.py install" \
             --copy . /home/bm \
             --run-bash "chmod a+x /home/bm/bidsonym/fs_data/mri_deface" \
             --run-bash "source activate bidsonym && cd /home/bm && pip install -e ." \
             --env IS_DOCKER=1 \
             --workdir '/tmp/' \
             --entrypoint "/neurodocker/startup.sh  bidsonym"

The relevant command where things fail is this one:

--run-bash "mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && conda activate bidsonym && datalad datalad clone https://github.com/neuronets/trained-models && cd trained-models && git-annex enableremote osf-storage && datalad get -s osf-storage ."

And it fails by telling me:

> [ 5/13] RUN bash -c 'mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && conda activate bidsonym && datalad datalad clone https://github.com/neuronets/trained-models && cd trained-models && git-annex enableremote osf-storage && datalad get -s osf-storage .':                                                                                                                 
#0 2.056                                                                                                                        
#0 2.056 CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.                             
#0 2.056 To initialize your shell, run
#0 2.056 
#0 2.056     $ conda init <SHELL_NAME>
#0 2.056 
#0 2.056 Currently supported shells are:
#0 2.056   - bash
#0 2.056   - fish
#0 2.056   - tcsh
#0 2.056   - xonsh
#0 2.056   - zsh
#0 2.056   - powershell
#0 2.056 
#0 2.056 See 'conda init --help' for more information and options.
#0 2.056 
#0 2.056 IMPORTANT: You may need to close and restart your shell after running 'conda init'.
#0 2.056 
#0 2.056 
------
ERROR: failed to solve: executor failed running [/bin/sh -c bash -c 'mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && conda activate bidsonym && datalad datalad clone https://github.com/neuronets/trained-models && cd trained-models && git-annex enableremote osf-storage && datalad get -s osf-storage .']: exit code: 1
stebo85 commented 1 year ago

Could you install the conda packages to the base environment instead of your bidsonym environment? Then you wouldn't need to activate it?

This should work?

   --miniconda \
         version=latest \
         conda_install='python=3.10 numpy nipype nibabel pandas' \
         pip_install='deepdefacer tensorflow scikit-image pydeface==2.0.2 nobrainer==0.4.0 quickshear==1.2.0 datalad datalad-osf' \
Remi-Gau commented 1 year ago

Will try

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.