{"id":15489905,"url":"https://github.com/rene-d/from-scratch","last_synced_at":"2025-10-12T03:31:28.679Z","repository":{"id":77191617,"uuid":"196689864","full_name":"rene-d/FROM-scratch","owner":"rene-d","description":"Static compilation and bare container demo ","archived":true,"fork":false,"pushed_at":"2019-07-16T21:50:41.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T09:40:41.293Z","etag":null,"topics":["alpine-linux","docker","static-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rene-d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-13T07:01:40.000Z","updated_at":"2023-10-09T17:02:00.000Z","dependencies_parsed_at":"2023-09-04T13:16:24.235Z","dependency_job_id":null,"html_url":"https://github.com/rene-d/FROM-scratch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rene-d/FROM-scratch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rene-d%2FFROM-scratch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rene-d%2FFROM-scratch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rene-d%2FFROM-scratch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rene-d%2FFROM-scratch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rene-d","download_url":"https://codeload.github.com/rene-d/FROM-scratch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rene-d%2FFROM-scratch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010148,"owners_count":26084692,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["alpine-linux","docker","static-library"],"created_at":"2024-10-02T07:08:38.825Z","updated_at":"2025-10-12T03:31:28.673Z","avatar_url":"https://github.com/rene-d.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FROM scratch\n\n[![](https://images.microbadger.com/badges/version/rene2/fromscratch.svg)](https://microbadger.com/images/rene2/fromscratch \"Get your own version badge on microbadger.com\")[![](https://images.microbadger.com/badges/image/rene2/fromscratch.svg)](https://microbadger.com/images/rene2/fromscratch \"Get your own image badge on microbadger.com\")\n\n\nDemonstration of creating a base image that contains a statically-linked program.\n\n## The background\n\nIn classic Linux distro, some libraries are available only for dynamic linking (ex: GLib). Even the [glibc](https://www.gnu.org/software/libc/) requires a dynamically loaded library for some functions ([read here](https://stackoverflow.com/questions/2725255/create-statically-linked-binary-that-uses-getaddrinfo)).\n\n\u003e Indeed, on [`getaddrinfo()`](https://linux.die.net/man/3/getaddrinfo) calls, static and dynamic flavours of `glibc` always **dynamically** load at least `libnss_files.so.2` which depends on `libc.so` itself. So you *cannot* make a static self-sufficient executable that uses `getaddrinfo()` API with the standard `glibc`.\n\nIn order to create an [empty Docker image](https://docs.docker.com/develop/develop-images/baseimages/) that contains just an executable, you will need statically linked program that will not require or load any dynamic libraries, since the image will not have any shared libraries.\n\nThe best choice is to use [musl-libc](https://www.musl-libc.org) and [Alpine Linux](https://alpinelinux.org), where all the hard work has already be done.\n\n## The Docker image\n\nThe Docker image uses a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/).\n\n- The first stage prepares the build environment (compiler and libraries).\n- The second one creates a bare image with only the program and its data.\n\n## Running the demo\n\n### From the Docker registry\n\n```bash\ndocker run --rm -ti rene2/fromscratch\n```\n\nNota: This image is made by the automated build system on _Docker Hub's infrastructure_.\n\n### With a fresh image\n\nThe [demo.sh](demo.sh) script builds and inspects the image ([jq](https://stedolan.github.io/jq/) is required to filter the [inspect](https://docs.docker.com/engine/reference/commandline/inspect/) output, or comment line 8).\n\nThen, it runs the unique executable (`a.out`) in the container.\n\n![demo.png](https://raw.githubusercontent.com/rene-d/FROM-scratch/master/demo.png)\n\n\n## To go further\n\nSome [explanations](details.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frene-d%2Ffrom-scratch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frene-d%2Ffrom-scratch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frene-d%2Ffrom-scratch/lists"}