Giter Club home page Giter Club logo

stfd's Introduction

Slim-The-Filesystem-Down (docker-stfd)

docker-stfd is a tool which massively reduces the size of existing Docker images by running them, monitoring what files in the filesystem are actually being used, deleting the ones that aren't, then rebuilding the top image layers into one. It makes use of dockerfile-from-image.

This will only work in the case that the exact same set of files are accessed each time a container is run, otherwise docker-stfd will not know which are safe to delete. It will also leave your container in a highly volatile state, with anything other than the original command unlikely to work.

Nevertheless, this is useful for containers which perform a straighforward deterministic calculation each time, and where size if very important. For example, we use docker-stfd to slim down images before sending them to the volunteers at Cosmology@Home.

Usage

If you would normally run your container with,

docker run <image> <cmd>

then,

docker-stfd <image> <cmd>

creates a slimmed down version (with default name <image>-slim).

Notes

  • If your <cmd> contains the same option flags as docker-stfd, you must use -- to separate them, i.e. docker-stfd <image> -- <cmd>.
  • If running your container takes a long time, but you are sure that, e.g. within the first X seconds all of the necessary files have been accessed, a useful trick is to run timeout X <cmd> instead of <cmd>.

Example

$ ./docker-stfd myimage:latest timeout 10 python mycode.py
Reverse engineering Dockerfile...
Inspecting container file usage...
Getting image filesystem...
Getting base filesystem...
Creating new slimmed filesystem...
Building new container...
Created image myimage:latest-slim
Uncompressed size shrunk from 644.6 MB to 211.6 MB

Requirements

  • Your host system needs strace and docker installed.
  • The container will needs some basic commands like find, grep, sort, and readlink. Most Debian/Ubuntu guests have this by default. This is not yet compatible with Busybox's grep. I have not tested others.

TODO

  • Support for other guest distros
  • Pass other docker options
  • Slim at a different layer than the FROM layer
  • Package up inside Docker

stfd's People

Contributors

marius311 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

stfd's Issues

Getting Error

When I run
./docker-stfd mtrnord/projectstreet_detection:latest sh -c "PYTHONPATH='/usr/lib/python2.7/dist-packages/' python face_detect.py abba.png haarcascade_frontalface_default.xml >> /root/shared/results/logs.txt"

I get

Reverse engineering Dockerfile...
Traceback (most recent call last):
  File "./docker-stfd", line 73, in <module>
    baseimage = next(l for l in dockerfile if l.startswith('FROM')).split()[1]
StopIteration

I run that inside an docker container (if that makes any difference)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.