Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Container image minimizer

License

NotificationsYou must be signed in to change notification settings

w-vi/ocidiet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Experimntal container image minimizer. Usesldd and can possibly usestrace in the future to detect the files needed by a binary. It minimizesthe image size because it copies only files needed into a tar which than canbeADDed to for examplebusybox:uclibc image or from scratch.

Prerequisites

  • Python 2.7 or Python 3+
  • ldd -ldd(1)

What can be done with it?

There are two main use cases.

  • building smaller images from other base images
  • building images from local environment

Build small node.js app from offical node image

Using the offical node 6 image

$ docker run -ti -v $(pwd):/usr/src/app node:6 bash

Inside the node:6 container install your app

> cd /usr/src/app> npm install> ./ocidiet.py -t myapp.tar -b `which node` -e /etc/nsswitch.conf \  /etc/resolv.conf myapp/node_modules myapp/package.json myapp/index.js> exit

and finally on the host build you final app image

# docker build -t myapp .

using the followingDockerfile:

FROM busybox:uclibcADD myapp.tar /ENTRYPOINT ["/usr/local/bin/node"]CMD ["/usr/src/app/myapp/index.js"]

Now you have a node image which has roughly 37 MB + size of your app.

Create image from local environment

Another option usefull for quick shipping and sharing is to use it forcreating images based on local dev environment. Usefull for compiledC/C++ projects.

Taking the hello world example

#include<stdio.h>intmain(void) {printf("Hello World\n");return0;}

and compiling it withgcc hello.c -o hello we now have an app whichneeds at least libc. If we install it to let's say/usr/local/bin wecan create a container image by first creating the tar

$ ./ocidiet.py -t hello.tar -b /usr/local/bin/hello

and then using the following Dockerfile

FROM busybox:uclibcADD hello.tar /ENTRYPOINT ["/usr/local/bin/hello"]

building the final image.

$ docker build -t hello.

which contains really just thebusybox:uclibc files and thehellobinary and correct version oflibc.

If you don't need the busybox to poke around the running containerjust build it from scratch.

FROM scratchADD hello.tar /ENTRYPOINT ["/usr/local/bin/hello"]

and save around 1.2 MB.

About

Container image minimizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp