从 Nipype docker image CommandNotFound 构建奇点配方

Building Singularity recipe from Nipype docker image CommandNotFound

我有以下奇点容器配方:

#!/bin/bash

Bootstrap: docker
From: nipype/nipype:latest

%labels
  Version v1.0

%post
  # Install nano
  apt-get update
  apt-get install nano

  # Set up Python environment
  CONDA_ENV=/opt/conda/bin
  export PATH=$CONDA_ENV:$PATH
  chmod -R 777 $CONDA_ENV

  # Activate conda environment
  conda activate neuro
  conda install seaborn
  pip install pybids

我用 Singularity 构建容器如下:

sudo singularity build swish.simg Singularity.swish

依赖项的安装和大部分构建都正常,直到我遇到 source not found 的错误。重申这个问题和我已经尝试过的:

问题归结为您激活环境的方式。通常,您会这样做:

source /opt/conda/bin/activate neuro

但如果 Singularity 容器 post 是在 shell (sh) 环境中构建的,则预计您不会找到 source 命令。相反你想做:

. /opt/conda/bin/activate neuro

然后你就不需要为 $PATH 大惊小怪了。您也不需要在文件顶部指定解释器。所以整个食谱应该是这样的:

Bootstrap: docker
From: nipype/nipype:latest

# This is the adjusted (fixed) build recipe for the issue above.
# sudo singularity build swist Singularity.swist

%labels
    Version v1.0

%environment
    . /opt/conda/bin/activate neuro

%post
    # Install nano
    apt-get update && apt-get install -y nano

    # Install into conda environment
    . /opt/conda/bin/activate neuro &&
    /opt/conda/bin/conda install --name neuro -y seaborn &&
    /opt/conda/envs/neuro/bin/pip install pybids

然后用法为:

sudo singularity build swist Singularity.swist

singularity/swist_fmri_image>   . /opt/conda/bin/activate neuro

(neuro) Singularity swist:~/swist-> python
Python 3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:39:56) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import seaborn
>>> import bids
>>>

我已经把整个记录放在 gist

有用的调试技巧

这里有一些有用的调试技巧!我想出上面的方法是做一个构建,用触发错误的 conda 注释掉最后几行。然后我可以构建一个可写的沙箱:

sudo singularity build --sandbox swist-box Singularity.swist

和 shell 是可写的。这将允许我进行更改和测试。

sudo singularity shell --writable swist-box
$ whoami
root

由于容器是可写的,这意味着更改会持续存在,因此您可以退出 root,然后在用户 space 中进行编辑以测试您的 root 更改是否确实解决了问题!

singularity shell swist-box
$ whoami
neuro

然后当你认为一切正常时,删除图像并从头开始构建并测试。

rm -rf swist-box swist
sudo singularity build swist Singularity.swist