【问题标题】:How to install pip into a ubuntu container while keeping layers to a minimum? [closed]如何将 pip 安装到 ubuntu 容器中,同时将层保持在最低限度? [关闭]
【发布时间】:2018-11-23 11:31:56
【问题描述】:

我有兴趣构建一个包含 pip 安装包的小型容器映像,但不幸的是,通过 apt-get 安装 python3-pip 会将 lot 的依赖项 (348MB) 拉入另一个非常小的最小 ubuntu 图像(我目前正在使用来自 dockerhub 的 ubuntu:xenial 图像):

root@dce44a07a6a5:/home# apt-get install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dirmngr dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base gir1.2-glib-2.0 gnupg gnupg-l10n
  gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libassuan0 libatomic1 libbinutils
  libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-7-dev libgdbm-compat4 libgdbm5 libgirepository-1.0-1 libglib2.0-0
  libglib2.0-data libgomp1 libicu60 libisl19 libitm1 libksba8 liblocale-gettext-perl liblsan0 libmpc3 libmpfr6 libmpx2 libnpth0 libperl5.26 libpython3-dev libpython3.6 libpython3.6-dev
  libquadmath0 libstdc++-7-dev libtsan0 libubsan0 libxml2 linux-libc-dev make manpages manpages-dev netbase patch perl perl-modules-5.26 pinentry-curses python-pip-whl python3-asn1crypto
  python3-cffi-backend python3-crypto python3-cryptography python3-dbus python3-dev python3-distutils python3-gi python3-idna python3-keyring python3-keyrings.alt python3-lib2to3
  python3-pkg-resources python3-secretstorage python3-setuptools python3-six python3-wheel python3-xdg python3.6-dev shared-mime-info xdg-user-dirs
Suggested packages:
  binutils-doc cpp-doc gcc-7-locales dbus-user-session libpam-systemd pinentry-gnome3 tor debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib autoconf
  automake libtool flex bison gdb gcc-doc gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg
  libmpx2-dbg libquadmath0-dbg parcimonie xloadimage scdaemon glibc-doc git bzr gdbm-l10n libstdc++-7-doc make-doc man-browser ed diffutils-doc perl-doc libterm-readline-gnu-perl
  | libterm-readline-perl-perl pinentry-doc python-crypto-doc python-cryptography-doc python3-cryptography-vectors python-dbus-doc python3-dbus-dbg gnome-keyring libkf5wallet-bin
  gir1.2-gnomekeyring-1.0 python-secretstorage-doc python-setuptools-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dirmngr dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base gir1.2-glib-2.0 gnupg gnupg-l10n
  gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libassuan0 libatomic1 libbinutils
  libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-7-dev libgdbm-compat4 libgdbm5 libgirepository-1.0-1 libglib2.0-0
  libglib2.0-data libgomp1 libicu60 libisl19 libitm1 libksba8 liblocale-gettext-perl liblsan0 libmpc3 libmpfr6 libmpx2 libnpth0 libperl5.26 libpython3-dev libpython3.6 libpython3.6-dev
  libquadmath0 libstdc++-7-dev libtsan0 libubsan0 libxml2 linux-libc-dev make manpages manpages-dev netbase patch perl perl-modules-5.26 pinentry-curses python-pip-whl python3-asn1crypto
  python3-cffi-backend python3-crypto python3-cryptography python3-dbus python3-dev python3-distutils python3-gi python3-idna python3-keyring python3-keyrings.alt python3-lib2to3
  python3-pip python3-pkg-resources python3-secretstorage python3-setuptools python3-six python3-wheel python3-xdg python3.6-dev shared-mime-info xdg-user-dirs
0 upgraded, 98 newly installed, 0 to remove and 2 not upgraded.
Need to get 108 MB of archives.
After this operation, 348 MB of additional disk space will be used.

其中很多是为了编译 c 模块。我想知道在构建容器时是否有替代使用 pip 安装 python 模块的方法。

也许有一种程序化的方式来安装 pip,安装依赖,然后在同一个 docker 层中干净地卸载 pip?

即(释义):

RUN  install_pip && pip install mymod && uninstall_pip

【问题讨论】:

    标签: python docker ubuntu pip


    【解决方案1】:

    如果您必须坚持使用 ubuntu,请使用 apt-get install --no-install-recommends python3-pip。它只需要 33.9 MB,少了 10 倍。最终成像为 146M。

    如果您能够使用 debian,请使用 python:3.6-slim 作为基础映像 (138M),若要进一步推送,请使用 python:alpine(78.2M)。

    对于最后 2 种情况,您可以使用 python3 -m pip uninstall pip setuptools 删除 pip,但由于层开销,它实际上使其更大。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      相关资源
      最近更新 更多