• Stars
    star
    206
  • Rank 186,140 (Top 4 %)
  • Language
    Shell
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimal Docker images: a collection of Dockerfiles illustrating how to reduce container image size.

minimage

Examples and experiments with multi-stage builds, static binaries, and other techniques to obtain MINimal IMAGEs.

This repository contains code samples and Dockerfiles to illustrate a series of blog posts about image size optimization. You can read this series in English: part 1, part 2, part 3; or in French: part 1, part 2, part 3.

Ingredients

This repository contains some sample code:

  • hello.c: hello world in C
  • hello.go: hello world in Go
  • hello.py: hello world in Python
  • hello.rs: hello world in Rust
  • pyds.py: doesn't do anything except import a few data science packages
  • pyyaml.py: doesn't do anything excpet import yaml (PyYAML)
  • whatsmyip.go: Go code making one HTTP request to canihazip.com

And a bunch of Dockerfiles to build that code.

Wow that's a lot of Dockerfiles

The goal is to show many combinations of build and run stages: do they work? What's the size of the final image?

Each Dockerfile has a pretty long name, with the following convention:

Dockerfile.PROGRAM-TO-BUILD.BUILD-IMAGE[.RUN-IMAGE]

So, for instance, Dockerfile.hello-java.openjdk-8.openjdk-8-jre-alpine means that the Dockerfile builds the hello.java code sample, using openjdk:8 as the build stage, and openjdk:8-jre-alpine as the run stage.

For single-stage builds (like Dockerfile.hello-rust.rust-alpine) there is no RUN-IMAGE.

Sometimes, the name of the Dockerfile also includes special build parameters, for instance:

  • Dockerfile.hello-c.alpine-static.scratch doesn't mean that the build stage is using an image named alpine:static, but that it's using alpine and building the program with extra flags to generate a static binary;
  • Dockerfile.whatsmyip.golang-nocgo.scratch doesn't mean that the build stage is using an image named golang:nocgo, but that it's using golang and building the program with extra options to disable cgo.

Show me the sizes of the images!

If you want to compare the sizes of all these images, you can do:

docker-compose build
docker images minimage | sort

Do these images all work?

No! Some of them won't. This shows that some combinations of build and run images are invalid, for reasons explained in the supporting blog post.

If you want to test these images, you can do:

docker-compose up
docker-compose ps

The images that work will show Exit 0. If you want to check what's wrong with the ones that show something else (like Exit 1 or Exit 127), you can run e.g. docker-compose up whatsmyip.golang.scratch or docker run minimage:whatsmyip.golang.scratch.

Python wheels

Check the pyds and pyyaml examples to see how to leverage multi-stage builds with Python on Alpine. This is useful for Python packages that use native code. When installing these packages on a glibc system, Python can download pre-compiled versions of the packages; but on Alpine (which uses musl) Python cannot use the pre-compiled versions, and it must recompile.

This recompilation can take a lot of time and disk space, especially on big data science packages like numpy, scipy, pandas...

If you want small images with Python and data science workloads (or anything that requires native code), the easiest solution is to use python:slim. But if you really want to use python:alpine, you can build wheels in a first stage, and install them in a second stage, as is done here in pyds and pyyaml.

This is not perfect (we end up copying the wheels before installing them, which wastes a bit of disk space), but I hope you'll find it helpful anyway!

Extra info

The Compose file is generated automatically using the script mkcompose.sh.

There are some Dockerfiles that won't even build. These ones have the special extension .err and added to a separate Compose file, because having them in the same Compose file would break the build of the others (Compose stops as soon as one build fails).

Contributing

If you want to add code samples or Dockerfiles, feel free to!

More Repositories

1

pipework

Software-Defined Networking tools for LXC (LinuX Containers)
Shell
4,139
star
2

container.training

Slides and code samples for training, tutorials, and workshops about Docker, containers, and Kubernetes.
Shell
3,559
star
3

nsenter

Shell
2,582
star
4

ampernetacle

HCL
2,519
star
5

dind

Docker in Docker
Shell
2,474
star
6

dockvpn

Recipe to build an OpenVPN image for Docker
Shell
833
star
7

squid-in-a-can

Python
357
star
8

pxe

Dockerfile to build a PXE server in a Docker container
Shell
250
star
9

griode

Griode + Novation Launchpad + Raspberry Pi = a music instrument!
Python
139
star
10

registrish

Dirty hack to run a read-only, public Docker registry on almost any static file hosting service (e.g. NGINX, Netlify, S3...)
Shell
136
star
11

shpod

Container image to get a consistent training environment to work on Kubernetes.
Dockerfile
134
star
12

critmux

Docker + CRIU + tmux = magic!
Dockerfile
117
star
13

dockercoins

Python
98
star
14

docker-busybox

Busybox for Stackbrew
Shell
94
star
15

sekexe

Separate Kernel Execution: execute a process within user-mode-linux and retrieve its output and status code
Shell
79
star
16

dessine-moi-un-cluster

Instructions to build a Kubernetes control plane one piece at a time, for learning purposes.
Shell
78
star
17

gunsub

Get your github notifications under control!
Python
74
star
18

syslogdocker

70
star
19

stevedore

Containerize your development environments
Shell
68
star
20

hamba

Shell
67
star
21

obs-docker

OBS-Studio (and a few extra tools) in containers
Python
62
star
22

docker2docker

Shell
26
star
23

wordsmith

Java
23
star
24

intro-to-docker

CSS
23
star
25

jpetazzo.github.io

HTML
22
star
26

go-docker-

20
star
27

trainingwheels

HTML
18
star
28

snakedeck

Elgato StreamDeck controller for Linux, in Python.
Python
17
star
29

nsplease

Tiny Kubernetes operator to create Namespaces on demand (for CI/CD, for instance)
Shell
16
star
30

django

Django on DotCloud tutorial
Python
16
star
31

whisperfiles

A bunch of Dockerfiles for OpenAI Whisper, to illustrate various image optimization techniques
Shell
15
star
32

foundation-example

Shell
14
star
33

httpenv

Tiny HTTP server showing the environment variables
Go
14
star
34

buildkit-demos

Dockerfile
13
star
35

dctrl

Shell
13
star
36

orchestration-workshop

We have moved! We are now at โ†’ https://github.com/jpetazzo/container.training
HTML
12
star
37

decoup

Python
11
star
38

layeremove

Surgically remove layers from a Docker image (with a chainsaw)
Python
11
star
39

znc-on-dotcloud

Shell
11
star
40

tilestream-on-dotcloud

Python
10
star
41

littleboxes

Just for fun scripts to manage local cloud-like VMs with KVM
Shell
10
star
42

django-and-mongodb-on-dotcloud

Django on DotCloud tutorial, using MongoDB to store objects!
Python
10
star
43

kubercoins

8
star
44

sstk

Shell
8
star
45

geodjango-on-dotcloud

Python
7
star
46

meteor-on-dotcloud

7
star
47

solr-on-dotcloud

JavaScript
7
star
48

seleterm

Selenium for terminal applications
Python
6
star
49

snap-on-dotcloud

Shell
6
star
50

httplat

Minimalist Prometheus exporter to collect the latency of an HTTP target
Go
6
star
51

boggle

Solver for the Boggle Word Game
Python
6
star
52

mume

Python
6
star
53

gitorial

(Ab)use git history to write tutorials!
Python
6
star
54

postgresql-on-dotcloud

Python
5
star
55

django-on-gpaas

Django on GANDI PAAS
Python
5
star
56

scangraph

Retrieve point coordinates from a raster plot
JavaScript
5
star
57

hano

Online IDE for Node.js on dotCloud
Shell
5
star
58

pyramid-on-dotcloud

Python
5
star
59

traefik-compose

Quick demo showing how to run web sites (like Wordpress) on Docker with Traefik
4
star
60

plumber

Shell
4
star
61

consul

jpetazzo's Consul image
Shell
4
star
62

zwave-exporter

Prometheus exporter for Z-Wave sensors
JavaScript
4
star
63

jenkins-on-dotcloud

Shell
4
star
64

color

Go
4
star
65

busyhttp

A trivial HTTP server that eats CPU cycles at each request.
Python
4
star
66

tinydocgen

Tiny document generator using Jinja2, Markdown, and WeasyPrint.
Makefile
3
star
67

ngrok

3
star
68

charliebot

Python
3
star
69

prettypictures

3
star
70

usb-webcam-analyzer

Python
3
star
71

rickroll-in-docker

HTML
3
star
72

dnc

Domain Name Command-line tool
Python
3
star
73

python-simple-logging

Python
3
star
74

replay.container.training

Shell
3
star
75

riak-on-dotcloud-ALPHA

Shell
3
star
76

ucengine-on-dotcloud-ALPHA

Shell
3
star
77

django-r2d2

R2D2 (RRDDashboard) is a Django application to draw graphs from metrics coming from e.g. collectd.
Python
3
star
78

pieuvre

Distributed HTTP proxy in Node.js
JavaScript
2
star
79

tmp-sealedsecret-juin-2022

2
star
80

couchdb-on-dotcloud-ALPHA

Shell
2
star
81

escapehash

Python
2
star
82

dockerhubratelimit

Shell
2
star
83

workflows

2
star
84

python-worker-on-dotcloud

Shell
2
star
85

tcl-on-dotcloud-ALPHA

Shell
2
star
86

elastic-gke

HCL
2
star
87

dampmam

Docker-Apache-MySQL-PHP but without Apache and MySQL
JavaScript
2
star
88

watchdns

Shell
2
star
89

highfive

Dockerfile
2
star
90

memcached-on-dotcloud

2
star
91

pawd

PulseAudio Web Daemon
2
star
92

pingr

HTTP server to ping other servers and report their status
Go
2
star
93

dotfiles-old

Config files for various environments
Shell
2
star
94

pgpool-II-on-dotcloud

2
star
95

ls

An ls image for the Docker Fundamentals training
Shell
2
star
96

jetty-on-dotcloud

Reimplementation of dotCloud java service using the custom build API
Shell
2
star
97

dockage

Shell
2
star
98

jira-on-dotcloud

Shell
2
star
99

tornado-on-dotcloud

Python
2
star
100

aiguillage

Nginx
2
star