我有兴趣构建一个包含pip安装包的小型容器映像,但是不幸的是,通过apt-get安装python3-pip将依赖项(348MB)中的 lot 拉入到其他容器中很小的最小ubuntu映像(我目前正在使用dockerhub的<50MB account.save()
映像):
ubuntu:xenial
很多都是用于编译c模块。我想知道在构建容器时是否可以使用pip来安装python模块。
也许有一种编程方式可以安装pip,安装依赖项,然后在同一docker层中干净地卸载pip?
即(措辞):
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.
答案 0 :(得分: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)进一步推送它。
在最后两种情况下,您可以使用python3 -m pip uninstall pip setuptools
删除点,但是由于层开销,实际上会使它变大。