recherche

Maison  >  Questions et réponses  >  le corps du texte

node.js - Centos镜像大小优化

开发的时候要用到nodejs,node-canvas, node-opencv,所以安装了cairoopencv,但是制作好镜像发现镜像大了300多M(其实一开始多了700多M,只写一句RUN的办法不再讨论),下面看Dockerfile:

FROM centos:7 # 没用alpine,安装各种包alpine还是有点麻烦,尝试过后放弃了
MAINTAINER ykan <nameyukan@gmail.com>

ENV PKG_CONFIG_PATH /usr/lib64/pkgconfig
ENV USER root
WORKDIR /root

## 配置yum
COPY CentOS7-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo

# 只执行一句RUN,镜像大小从900多M,减少到500多M
RUN curl -O http://cdn.npm.taobao.org/dist/node/v6.9.1/node-v6.9.1-linux-x64.tar.gz && \
  tar --strip-components 1 -xzvf node-v* -C /usr/local && \
  node --version && \
  # 配置淘宝源
  npm config set registry https://registry.npm.taobao.org && \
  yum clean all && yum makecache && \
  # 安装工具
  yum install -y gcc automake autoconf libtool make gcc-c++ \
  # node-canvas的依赖
  cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel \
  # opencv的依赖
  opencv opencv-devel && \
  npm install canvas opencv -g --unsafe-perm --verbose && \
  # 移除工具
  yum remove -y gcc automake autoconf libtool make gcc-c++  \
  # 移除开发需要的模块,这个操作减少了3M的体积
  cairo-devel cairomm-devel libjpeg-turbo-devel pango-devel pangomm-devel giflib-devel  opencv-devel && \
  yum clean all && \
  rm -rf node-v6.9.1-linux-x64.tar.gz \ 
    /usr/share/man \ 
    /tmp/* \ 
    /var/cache/yum \
    /usr/local/share/doc \
    /usr/local/share/man \
    /usr/lib/node_modules/npm/man \ 
    /usr/lib/node_modules/npm/doc \ 
    /usr/lib/node_modules/npm/html 

但是,还是大了300多M:

$ docker images # 省略了一些输出
REPOSITORY      TAG      SIZE
opencv-canvas   latest   517 MB
centos          7        192 MB

那么多出来的是啥呢!我只好进去再看看:

~ docker run -it opencv-canvas
~ docker run -it centos:7

放大招,通过du -h | grep "[0-9]M"来看看各个目录的大小,最后发现/user下多了很多,安装后的:

~ du -h | grep "[0-9]M"
2.1M    ./local/include/node/openssl
2.9M    ./local/include/node
2.9M    ./local/include
1.1M    ./local/lib/node_modules/canvas/build/Release
1.1M    ./local/lib/node_modules/canvas/build
1.9M    ./local/lib/node_modules/canvas
2.7M    ./local/lib/node_modules/opencv/examples/files
1.6M    ./local/lib/node_modules/opencv/examples/coffeescript
4.4M    ./local/lib/node_modules/opencv/examples
1.5M    ./local/lib/node_modules/opencv/node_modules/uglify-js
2.4M    ./local/lib/node_modules/opencv/node_modules/handlebars/dist
2.9M    ./local/lib/node_modules/opencv/node_modules/handlebars
17M    ./local/lib/node_modules/opencv/node_modules
1.1M    ./local/lib/node_modules/opencv/build/Release/obj.target/opencv/src
1.1M    ./local/lib/node_modules/opencv/build/Release/obj.target/opencv
1.7M    ./local/lib/node_modules/opencv/build/Release/obj.target
2.4M    ./local/lib/node_modules/opencv/build/Release
2.9M    ./local/lib/node_modules/opencv/build
19M    ./local/lib/node_modules/opencv/data
44M    ./local/lib/node_modules/opencv
1.1M    ./local/lib/node_modules/npm/node_modules/npm-registry-client
2.1M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext
2.2M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules
2.2M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol
2.3M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules
2.4M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index
2.4M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules
2.4M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules/path-array
3.0M    ./local/lib/node_modules/npm/node_modules/node-gyp/node_modules
1.5M    ./local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp
1.5M    ./local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib
1.9M    ./local/lib/node_modules/npm/node_modules/node-gyp/gyp
5.1M    ./local/lib/node_modules/npm/node_modules/node-gyp
1.4M    ./local/lib/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules
1.5M    ./local/lib/node_modules/npm/node_modules/request/node_modules/http-signature
4.3M    ./local/lib/node_modules/npm/node_modules/request/node_modules
4.6M    ./local/lib/node_modules/npm/node_modules/request
16M    ./local/lib/node_modules/npm/node_modules
19M    ./local/lib/node_modules/npm
65M    ./local/lib/node_modules
65M    ./local/lib
29M    ./local/bin
96M    ./local
4.0M    ./include/unicode
1.5M    ./include/GL
2.4M    ./include/giomm-2.4/giomm
2.4M    ./include/giomm-2.4
1.3M    ./include/sigc++-2.0/sigc++
1.3M    ./include/sigc++-2.0
1.2M    ./include/freetype2/freetype
1.2M    ./include/freetype2
1.2M    ./include/glibmm-2.4/glibmm
1.2M    ./include/glibmm-2.4
2.7M    ./include/c++/4.8.2/bits
1.5M    ./include/c++/4.8.2/ext/pb_ds/detail
1.6M    ./include/c++/4.8.2/ext/pb_ds
2.4M    ./include/c++/4.8.2/ext
9.0M    ./include/c++/4.8.2
9.0M    ./include/c++
4.2M    ./include/linux
1.2M    ./include/glib-2.0/gio
2.3M    ./include/glib-2.0
2.1M    ./include/xcb
1.7M    ./include/X11
37M    ./include
5.6M    ./lib/udev/hwdb.d
6.0M    ./lib/udev
3.4M    ./lib/locale
8.3M    ./lib/systemd
2.4M    ./lib/python2.7/site-packages/yum
1.3M    ./lib/python2.7/site-packages/chardet
5.0M    ./lib/python2.7/site-packages
5.0M    ./lib/python2.7
1.1M    ./lib/dracut/modules.d
1.2M    ./lib/dracut
25M    ./lib
2.1M    ./lib64/girepository-1.0
1.3M    ./lib64/perl5/auto/Unicode/Collate
1.8M    ./lib64/perl5/auto/Unicode
3.0M    ./lib64/perl5/auto
2.4M    ./lib64/perl5/vendor_perl/auto/Encode/KR
2.7M    ./lib64/perl5/vendor_perl/auto/Encode/JP
2.0M    ./lib64/perl5/vendor_perl/auto/Encode/CN
2.0M    ./lib64/perl5/vendor_perl/auto/Encode/TW
9.4M    ./lib64/perl5/vendor_perl/auto/Encode
10M    ./lib64/perl5/vendor_perl/auto
12M    ./lib64/perl5/vendor_perl
1.6M    ./lib64/perl5/CORE
18M    ./lib64/perl5
2.7M    ./lib64/gstreamer-0.10
1.6M    ./lib64/nss/unsupported-tools
2.2M    ./lib64/nss
3.9M    ./lib64/python2.7/lib-dynload
2.3M    ./lib64/python2.7/encodings
3.4M    ./lib64/python2.7/site-packages
1.6M    ./lib64/python2.7/distutils
1.1M    ./lib64/python2.7/lib2to3
1.9M    ./lib64/python2.7/idlelib
29M    ./lib64/python2.7
7.3M    ./lib64/gconv
1.1M    ./lib64/security
166M    ./lib64
14M    ./libexec/gcc/x86_64-redhat-linux/4.8.2
14M    ./libexec/gcc/x86_64-redhat-linux
14M    ./libexec/gcc
15M    ./libexec
42M    ./bin
1.5M    ./share/xml/iso-codes
1.5M    ./share/xml
3.8M    ./share/perl5/unicore/lib
5.8M    ./share/perl5/unicore
1.7M    ./share/perl5/vendor_perl
6.7M    ./share/perl5/pod
1.1M    ./share/perl5/Unicode/Collate/Locale
3.1M    ./share/perl5/Unicode/Collate
3.2M    ./share/perl5/Unicode
21M    ./share/perl5
20M    ./share/OpenCV/haarcascades
20M    ./share/OpenCV
6.5M    ./share/hwdata
1.4M    ./share/icons/hicolor
1.4M    ./share/icons
1.1M    ./share/groff/1.22.2/font
1.9M    ./share/groff/1.22.2
1.9M    ./share/groff
2.0M    ./share/X11/locale
2.1M    ./share/X11
1.8M    ./share/mime/packages
1.5M    ./share/mime/application
4.8M    ./share/mime
9.0M    ./share/cracklib
1.7M    ./share/zoneinfo/right
1.7M    ./share/zoneinfo/posix
5.0M    ./share/zoneinfo
1.1M    ./share/pki/ca-trust-source
1.2M    ./share/pki
3.3M    ./share/i18n/charmaps
6.3M    ./share/i18n/locales
9.5M    ./share/i18n
2.8M    ./share/misc
91M    ./share
6.9M    ./sbin
476M    .

原来镜像的:

~ du -h | grep "[0-9]M"
3.4M    ./lib/locale
8.3M    ./lib/systemd
2.4M    ./lib/python2.7/site-packages/yum
1.3M    ./lib/python2.7/site-packages/chardet
5.0M    ./lib/python2.7/site-packages
5.0M    ./lib/python2.7
1.1M    ./lib/dracut/modules.d
1.2M    ./lib/dracut
19M    ./lib
1.6M    ./lib64/nss/unsupported-tools
2.2M    ./lib64/nss
3.9M    ./lib64/python2.7/lib-dynload
2.3M    ./lib64/python2.7/encodings
3.4M    ./lib64/python2.7/site-packages
1.6M    ./lib64/python2.7/distutils
1.1M    ./lib64/python2.7/lib2to3
1.9M    ./lib64/python2.7/idlelib
29M    ./lib64/python2.7
7.3M    ./lib64/gconv
1.1M    ./lib64/security
78M    ./lib64
38M    ./bin
6.9M    ./sbin
1.8M    ./share/mime/packages
1.5M    ./share/mime/application
4.8M    ./share/mime
9.0M    ./share/cracklib
1.7M    ./share/zoneinfo/right
1.7M    ./share/zoneinfo/posix
5.0M    ./share/zoneinfo
1.1M    ./share/pki/ca-trust-source
1.2M    ./share/pki
3.3M    ./share/i18n/charmaps
6.3M    ./share/i18n/locales
9.5M    ./share/i18n
2.8M    ./share/misc
37M    ./share
178M    .

那么问题来了!

我该删哪些呢~ 那个啥perl5和python可不可以删掉?

PHPzPHPz2786 Il y a quelques jours683

répondre à tous(1)je répondrai

  • 高洛峰

    高洛峰2017-04-17 16:07:12

    你这centos7 192,debian才99,官方推荐。

    répondre
    0
  • Annulerrépondre