我正在尝试创建基于 docker://python:3.7-buster
的奇点图像.
在 %post
部分,当我运行 /usr/bin/env python3
时使用了与我 singularity exec
时不同版本的 python同样的事情。
这是我的测试定义文件:
$ cat test.def
Bootstrap:docker
From:python:3.7-buster
%post
/usr/bin/env python3 --version
这是我尝试构建它时发生的情况:
$ sudo singularity build test.sif test.def
INFO: Starting build...
Getting image source signatures
Skipping fetch of repeat blob sha256:4a56a430b2bac33260d6449e162017e2b23076c6411a17b46db67f5b84dde2bd
Skipping fetch of repeat blob sha256:4b5cacb629f5c5323a32103e665756e5d50fe133b3db72d444f370566b713a6a
Skipping fetch of repeat blob sha256:14408c8d4f9a59a5da8f4cc40650be9a8d0991fa1ce1b2fb2767f289a9cc410d
Skipping fetch of repeat blob sha256:ea67eaa7dd42136287337f879ef20b4ee73baaa108d833d267ef99dd787cdcbf
Skipping fetch of repeat blob sha256:4d134ac3fe4b8dd8136d9e7acbb2708ead2154185b27c09ae62ca099070cfb27
Skipping fetch of repeat blob sha256:4c55f6f5d7f035e446f063331d9160bb00ed3da4632105ef5adedee3317c902f
Skipping fetch of repeat blob sha256:6ae475e50652d8ee1a2fdeb59ccce81d14c8c20e0fdfe94f22f1c69bd3e3befb
Skipping fetch of repeat blob sha256:6f41526442299286e270923d6cca3a516c3e1850f7e06c3facc0df7da8a5afbc
Skipping fetch of repeat blob sha256:6933d3d4604265f0c8f2a3806222749809c62b6e6a757d1f85720fa81622496d
Copying config sha256:5a5fb77dac35d62c5b062fc35b3b69e61ae68385fb4278ce6076532c3e50e316
7.47 KiB / 7.47 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
2019/09/16 11:07:07 info unpack layer: sha256:4a56a430b2bac33260d6449e162017e2b23076c6411a17b46db67f5b84dde2bd
2019/09/16 11:07:09 info unpack layer: sha256:4b5cacb629f5c5323a32103e665756e5d50fe133b3db72d444f370566b713a6a
2019/09/16 11:07:09 info unpack layer: sha256:14408c8d4f9a59a5da8f4cc40650be9a8d0991fa1ce1b2fb2767f289a9cc410d
2019/09/16 11:07:09 info unpack layer: sha256:ea67eaa7dd42136287337f879ef20b4ee73baaa108d833d267ef99dd787cdcbf
2019/09/16 11:07:11 info unpack layer: sha256:4d134ac3fe4b8dd8136d9e7acbb2708ead2154185b27c09ae62ca099070cfb27
2019/09/16 11:07:18 info unpack layer: sha256:4c55f6f5d7f035e446f063331d9160bb00ed3da4632105ef5adedee3317c902f
2019/09/16 11:07:18 info unpack layer: sha256:6ae475e50652d8ee1a2fdeb59ccce81d14c8c20e0fdfe94f22f1c69bd3e3befb
2019/09/16 11:07:19 info unpack layer: sha256:6f41526442299286e270923d6cca3a516c3e1850f7e06c3facc0df7da8a5afbc
2019/09/16 11:07:19 info unpack layer: sha256:6933d3d4604265f0c8f2a3806222749809c62b6e6a757d1f85720fa81622496d
INFO: Running post scriptlet
+ /usr/bin/env python3 --version
Python 3.7.3
INFO: Creating SIF file...
INFO: Build complete: test.sif
使用系统版本代替 docker 镜像提供的版本,这与我刚刚 exec
时发生的情况形成鲜明对比。相同的命令:
$ singularity exec docker://python:3.7-buster /usr/bin/env python3 --version
Python 3.7.4
会发生什么?
我尝试使用$(which python3)
而不是/usr/bin/env python3
,并且在%post
期间仍然是相同的版本。部分(使用 singularity exec
,它是使用的主机系统的版本)。
我的目标实际上是能够安装一些我从 git 存储库中提取的个人 python 软件包,并使用运行 /usr/bin/env python3 -m pip install -e .
的安装脚本进行安装。
我注意到有一个问题,因为python 3的系统版本不包括pip
.
最佳答案
由于环境不同,您将获得不同版本的 python。
如果你在 %post
中添加 echo $PATH
你会得到: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
如果你运行 singularity exec docker://python:3.7-buster bash -c 'echo $PATH'
你会得到: /usr/local/bin:/usr/本地/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local/bin/python3
是 docker 容器为您编译的较新版本,并且 %post
中的 PATH
优先考虑/usr/bin
覆盖 /usr/local/bin
。您可以调整 %post
block 开头的 PATH
变量来解决该问题。
至于为什么它在那里使用不同的PATH
,我不确定。可能值得在 github repo 提出问题.
关于python - 执行时和使用奇点构建镜像时的 python 版本不同,相同的官方 python docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57953793/