【问题标题】:Singularity container never has python in it?奇点容器中从来没有python?
【发布时间】:2020-08-28 23:19:41
【问题描述】:

我必须使用奇异性来打包我的代码以在学校服务器上运行。

我尝试仅从 python3.6-slim 映像构建一个基本容器,然后还在 %post 部分安装了 python 以进行良好的衡量。

我也尝试了其他一些基础,例如 debian buster 和 ubuntu 20.04。

目前定义文件如下:

Bootstrap: docker
From: ubuntu:20.04

%post
    # Downloads the latest package lists (important).
    apt-get update -y
    # Runs apt-get while ensuring that there are no user prompts that would
    # cause the build process to hang.
    apt-get update && apt-get install -y --no-install-recommends \
        python3.6

每次构建镜像后,我都尝试运行python --version,但它一直坚持:python: not found

我觉得我在文档中遗漏了一些明显的东西,但无法弄清楚我遗漏了什么。建立在官方 Python docker 镜像上的容器如何……没有安装 python?

【问题讨论】:

  • apt-get install -y --no-install-recommends python3.6 应该是apt-get install -y --no-install-recommends python3

标签: python docker containers singularity-container


【解决方案1】:

我尝试了以下定义文件:

Bootstrap: docker
From: ubuntu:20.04

%post
    apt-get update 
    apt-get install -y --no-install-recommends python3
    apt-get -y clean
    rm -rf rm -rf /var/lib/apt/lists/*

然后在shell中运行以下命令:

sudo singularity build ubuntu-python.sif ubuntu-python.def
singularity run ubuntu-python.sif

在容器中(将结果添加到命令下方):

Singularity> python3 -V
Python 3.8.2

将我的工作示例与您的示例进行比较,我发现了几个问题:

  • 你运行apt-get update 两次 - 一次就足够了
  • 您尝试安装包 python3.6 - Ubuntu 是基于 Debian 的发行版,与 Debian 一样,只有一个 python3 包,而不是每个 Python 3 版本的单独包
  • 你运行 python --version 而不是 python3 --version - 在 Ubuntu 中,pythonpython2 的别名,更多信息可以在 herehere 中找到。

您还提到了映像 python3.6-slim - 没有这样的 Docker 映像(我假设您在谈论 Docker 映像,因为您稍后会使用 Docker Ubuntu 映像)。但是,有python:3.6-slim 图像。这是我对 Singularity 使用它的快速测试:

singularity shell docker://python:3.6-slim
Singularity> python --version
Python 3.6.12
Singularity> python3 --version
Python 3.6.12

注意:我将singularity run 与基于Ubuntu 的映像一起使用,因为它的默认命令是bash。使用 python:3.6-slim 我必须使用 singularity shell 作为其默认命令启动交互式 Python shell。

编辑:如果您使用已安装 Python 的映像,则应该永远手动安装 Python - 您很可能会在同一个容器中以两个版本的 Python 3 结束,这将导致难以调试的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 2015-09-14
    相关资源
    最近更新 更多