从Nipype docker image CommandNotFound构建奇点配方 [英] Building Singularity recipe from Nipype docker image CommandNotFound

查看:58
本文介绍了从Nipype docker image CommandNotFound构建奇点配方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下奇点容器配方:

I have the following Singularity container recipe:

#!/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

我用如下方式构建容器:

and I build the container with Singularity as follows:

sudo奇点构建swish.simg Singularity.swish

依赖项和大多数构建的安装可以正常进行,直到出现未找到 source 的错误为止.要重申该问题以及我尝试过的操作:

The install of dependencies and majority of build goes OK until I hit the error that source not found. To reiterate the issue and what I've tried:

  • 我正在从食谱中制作一张Nipype图片.在%post中,我想在"neuro" conda环境中安装另外两个软件包(seaborn和pybids).
  • 但是,当我尝试激活%post(源激活神经")中的神经环境时,我不断收到一条错误消息,指出未找到命令源".
  • 我想用bash在%post中运行命令,但是不确定在哪里指定它.

推荐答案

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

The issue comes down to the way you are activating the environment. Normally, you would do:

source /opt/conda/bin/activate neuro

但是,如果在容器(sh)环境中构建Singularity容器帖子,则期望您找不到 source 命令.相反,您想这样做:

but in the case that the Singularity container post is building in a shell (sh) environment, the expectation is that you won't find the source command. Instead you want to do:

. /opt/conda/bin/activate neuro

,那么您无需大惊小怪的 $ PATH .您也不需要在文件顶部指定解释器.因此,整个食谱应如下所示:

and then you don't need to fuss with the $PATH. You also don't need to specify an interpreter at the top of the file. So the entire recipe should look like:

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

I've put the entire record of this in a gist

这里有一些有用的调试提示!我发现以上内容的方法是进行构建,并用触发错误的conda注释掉最后几行.然后,我可以构建一个可写的沙箱:

Here are a few helpful debugging tips! The way I figured out the above was to do a build commenting out the last lines with conda that triggered the error. Then I could build a writable sandbox:

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

并以可写的方式插入外壳.这让我可以进行更改和测试.

and shell in with writable. This wiil allow me to make changes and test.

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

由于容器具有可写性,这意味着更改将继续存在,因此您可以退出root用户身份,然后在用户空间中进行编辑以测试您的root用户更改是否确实解决了该问题!

Since the container would have writable, this means that changes would persist, so you can exit from being root, and then edit in user space to test if your root changes indeed fixed the issue!

singularity shell swist-box
$ whoami
neuro

然后,当您认为一切都很好时,请删除该图像,然后从头开始构建并进行测试.

Then when you think all is well, delete the image and build from scratch and test.

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

这篇关于从Nipype docker image CommandNotFound构建奇点配方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆