如何在执行时在Singularity容器中设置Python别名?

问题描述 投票:0回答:1

我一直在尝试在容器中设置一些别名,但我无法成功完成。在建造容器时,我把alias python3=python3.6放在%post,事情很好;别名已正确声明,并在整个容器构建过程中使用。

但是,在构建容器并执行它之后,使用singularity exec%environment or%runscript中的别名声明不起作用。我也尝试将别名声明命令放在容器中的bash脚本中并运行bash脚本,但它仍然不起作用。基本上,我认为我看起来像Docker中的ENTRYPOINT for Singularity。有谁知道我做错了什么以及如何在容器中设置别名?

我正在使用Singularity 2.6。

这是我正在使用的定义文件:

BootStrap: docker
From: ubuntu:16.04

%post
# Set up some required environment defaults
apt-get -y update && apt-get -y install software-properties-common && yes '' | add-apt-repository ppa:deadsnakes/ppa
apt-get -y update && apt-get -y install make \
                                        cmake \
                                        vim \
                                        curl \
                                        python3.6 \
                                        python3.6-dev \

curl https://bootstrap.pypa.io/get-pip.py | python3.6

alias python3=python3.6 #Here's where I declare the alias

python3 -m pip install -U pip
python3 -m pip install --upgrade pip
python3 -m pip install -U setuptools
python3 -m pip install  scipy \
                        numpy \
                        transforms3d \
                        matplotlib \
                        Pillow

# I also create a file containing a bash script to declare the alias
cd /
mkdir bash_aliases && cd bash_aliases
echo "alias python3=python3.6">bash_aliases.sh
chmod +x bash_aliases.sh


%runscript
alias python3=python3.6

# bash /bash_aliases/bash_aliases.sh # You may uncomment this as well
python-3.x bash docker alias singularity-container
1个回答
0
投票

虽然在使用容器时无法为exec模式设置别名,但是可以使用以下脚本为run模式执行此操作:

%runscript
    alias python3='python3.6'
    eval ${@}

execrun之间的区别在于exec运行你直接编写的命令,但run将你写的任何内容传递给你在%runscript中编写的脚本。

Source

© www.soinside.com 2019 - 2024. All rights reserved.