- Notifications
You must be signed in to change notification settings - Fork1
w-vi/ocidiet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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 canbeADD
ed to for examplebusybox:uclibc
image or from scratch.
- Python 2.7 or Python 3+
- ldd -ldd(1)
There are two main use cases.
- building smaller images from other base images
- building images from local environment
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.
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 thehello
binary 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
Uh oh!
There was an error while loading.Please reload this page.