{"id":13593474,"url":"https://github.com/jpetazzo/minimage","last_synced_at":"2025-04-09T05:31:14.882Z","repository":{"id":139777289,"uuid":"236286370","full_name":"jpetazzo/minimage","owner":"jpetazzo","description":"Minimal Docker images: a collection of Dockerfiles illustrating how to reduce container image size.","archived":false,"fork":false,"pushed_at":"2023-10-05T14:16:19.000Z","size":25,"stargazers_count":235,"open_issues_count":0,"forks_count":54,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-08-02T16:47:31.781Z","etag":null,"topics":["containers","docker","dockerfile","multi-stage"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpetazzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-26T08:36:05.000Z","updated_at":"2024-07-05T11:23:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"8028cd78-5cf1-4c54-af67-dc54ea8a8a47","html_url":"https://github.com/jpetazzo/minimage","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fminimage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fminimage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fminimage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fminimage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpetazzo","download_url":"https://codeload.github.com/jpetazzo/minimage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223365268,"owners_count":17133681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["containers","docker","dockerfile","multi-stage"],"created_at":"2024-08-01T16:01:20.674Z","updated_at":"2024-11-06T15:30:24.993Z","avatar_url":"https://github.com/jpetazzo.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# minimage\n\nExamples and experiments with multi-stage builds, static binaries, and\nother techniques to obtain MINimal IMAGEs.\n\nThis repository contains code samples and Dockerfiles\nto illustrate a series of blog posts about image size\noptimization. You can read this series in English:\n[part 1](https://www.ardanlabs.com/blog/2020/02/docker-images-part1-reducing-image-size.html),\n[part 2](https://www.ardanlabs.com/blog/2020/02/docker-images-part2-details-specific-to-different-languages.html),\n[part 3](https://www.ardanlabs.com/blog/2020/04/docker-images-part3-going-farther-reduce-image-size.html);\nor in French:\n[part 1](https://enix.io/fr/blog/cherie-j-ai-retreci-docker-part1/),\n[part 2](https://enix.io/fr/blog/cherie-j-ai-retreci-docker-part2/),\n[part 3](https://enix.io/fr/blog/cherie-j-ai-retreci-docker-part3/).\n\n\n## Ingredients\n\nThis repository contains some sample code:\n- hello.c: hello world in C\n- hello.go: hello world in Go\n- hello.py: hello world in Python\n- hello.rs: hello world in Rust\n- pyds.py: doesn't do anything except import a few data science packages\n- pyyaml.py: doesn't do anything excpet `import yaml` (PyYAML)\n- whatsmyip.go: Go code making one HTTP request to canihazip.com\n\nAnd a bunch of Dockerfiles to build that code.\n\n\n## Wow that's a lot of Dockerfiles\n\nThe goal is to show many combinations of build and run\nstages: do they work? What's the size of the final image?\n\nEach Dockerfile has a pretty long name, with the following convention:\n\n`Dockerfile.PROGRAM-TO-BUILD.BUILD-IMAGE[.RUN-IMAGE]`\n\nSo, for instance, `Dockerfile.hello-java.openjdk-8.openjdk-8-jre-alpine`\nmeans that the Dockerfile builds the `hello.java` code sample,\nusing `openjdk:8` as the build stage, and `openjdk:8-jre-alpine`\nas the run stage.\n\nFor single-stage builds (like `Dockerfile.hello-rust.rust-alpine`)\nthere is no `RUN-IMAGE`.\n\nSometimes, the name of the Dockerfile also includes\nspecial build parameters, for instance:\n\n- `Dockerfile.hello-c.alpine-static.scratch` doesn't mean\n  that the build stage is using an image named `alpine:static`,\n  but that it's using `alpine` and building the program with extra\n  flags to generate a static binary;\n- `Dockerfile.whatsmyip.golang-nocgo.scratch` doesn't mean\n  that the build stage is using an image named `golang:nocgo`,\n  but that it's using `golang` and building the program with\n  extra options to disable cgo.\n\n\n## Show me the sizes of the images!\n\nIf you want to compare the sizes of all these images, you can do:\n\n```bash\ndocker-compose build\ndocker images minimage | sort\n```\n\n\n## Do these images all work?\n\nNo! Some of them won't. This shows that some combinations\nof build and run images are invalid, for reasons explained\nin the supporting blog post.\n\nIf you want to *test* these images, you can do:\n```bash\ndocker-compose up\ndocker-compose ps\n```\n\nThe images that work will show `Exit 0`. If you want to check\nwhat's wrong with the ones that show something else (like\n`Exit 1` or `Exit 127`), you can run e.g.\n`docker-compose up whatsmyip.golang.scratch` or\n`docker run minimage:whatsmyip.golang.scratch`.\n\n\n## Python wheels\n\nCheck the `pyds` and `pyyaml` examples to see how to leverage\nmulti-stage builds with Python on Alpine. This is useful for\nPython packages that use native code. When installing these\npackages on a glibc system, Python can download pre-compiled\nversions of the packages; but on Alpine (which uses musl) Python\ncannot use the pre-compiled versions, and it must recompile.\n\nThis recompilation can take a lot of time and disk space,\nespecially on big data science packages like numpy, scipy,\npandas...\n\nIf you want small images with Python and data science workloads\n(or anything that requires native code), the easiest solution\nis to use `python:slim`. But if you really want to use `python:alpine`,\nyou can build wheels in a first stage, and install them in a\nsecond stage, as is done here in `pyds` and `pyyaml`.\n\nThis is not perfect (we end up copying the wheels before installing\nthem, which wastes a bit of disk space), but I hope you'll find it\nhelpful anyway!\n\n\n## Extra info\n\nThe Compose file is generated automatically using the script\n`mkcompose.sh`.\n\nThere are some Dockerfiles that won't even build. These ones\nhave the special extension `.err` and added to a separate\nCompose file, because having them in the same Compose file\nwould break the build of the others (Compose stops as soon\nas one build fails).\n\n\n## Contributing\n\nIf you want to add code samples or Dockerfiles, feel free to!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpetazzo%2Fminimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpetazzo%2Fminimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpetazzo%2Fminimage/lists"}