Python基本映像vs Ubuntu base image在d中单独安装Python

2024-10-01 13:37:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始学习docker将其应用到我的应用程序中。 当我在做的时候,我有一个问题。 请理解这可能是一个微不足道的问题。 我在码头是新来的。在

直观地说,使用OS(ubuntu)映像作为基础似乎比单纯的python更为沉重。在

这就是为什么我总是尝试只使用python图像作为基础,即使有一些使用ubuntu的用例。在

但是,我发现即使我使用pythonimage作为容器的基础,它仍然可以运行Linux(Ubuntu)命令,比如apt-getlsps),并且文件系统结构如ubuntuhome, root , usr)。在

它看起来仍然很小,像ubuntu。在

我知道如果我只使用ubuntu映像,我应该与python映像相比手动设置环境(如果我只想运行python)

除了方便性方面,它们有什么区别吗?我应该用python而不是ubuntu作为稳定性和性能的例子?在


Tags: docker图像命令应用程序osubuntulinuxapt
2条回答

好吧,正如viraptor所说,Python是一个不错的选择,但是它重900mb

Python映像的大小-为什么是900MB?在

https://github.com/docker-library/python/issues/30

YasserMartinez有一篇关于docker图像(实际上只有Python docker图像)大小的博客文章

http://yasermartinez.com/blog/posts/creating-super-small-docker-images.html

摘录

Python itself is not small, a typical python installation needs close to 100 MB once uncompressed on the disk. Of course one could imagine that here are many files included that aren't needed in most of the usual cases (like the turtle module). Is it possible to create a smaller python docker image? The answer is YES; if you now do a docker pull elyase/staticpython you will get a working python image with only 8.5 MB in size.

另见若昂·费雷拉·洛夫的github

https://github.com/jfloff/alpine-python

摘录

REPOSITORY TAG SIZE jfloff/alpine-python 2.7-slim 52.86 MB python 2.7-slim 180.8 MB

jfloff/alpine-python 2.7 234.2 MB python 2.7 676.2 MB

jfloff/alpine-python 3.4-slim 110.4 MB python 3.4-slim 193.9 MB

jfloff/alpine-python 3.4 280 MB python 3.4 681.5 MB

jfloff/alpine-python latest 248.8 MB python 3.5 685.4 MB

jfloff/alpine-python latest-slim 79.11 MB python 3.5-slim 197.8 MB

您可以在documentation中阅读python图像

有趣的是:

This tag is based off of buildpack-deps. buildpack-deps is designed for the average user of docker who has many images on their system. It, by design, has a large number of extremely common Debian packages.

并且buildpack-deps本身可以基于Debian或Ubuntu映像。在

正如他们在文档中提到的-如果您没有特定的要求,或者不知道为什么不使用另一个映像,那么python是一个不错的选择。在

将来,如果您希望部署映像比测试用的映像小(可能有一些额外的工具),您可能会对其他映像感兴趣。或者一般来说,您可能会试图使用尽可能小的大小来删除不必要的实用程序。做每一件事都有原因——你很可能会发现这些对你有什么意义。在

相关问题 更多 >