Coder Social home page Coder Social logo

from-scratch's Introduction

FROM scratch

Demonstration of creating a base image that contains a statically-linked program.

The background

In classic Linux distro, some libraries are available only for dynamic linking (ex: GLib). Even the glibc requires a dynamically loaded library for some functions (read here).

Indeed, on 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.

In order to create an empty Docker image 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.

The best choice is to use musl-libc and Alpine Linux, where all the hard work has already be done.

The Docker image

The Docker image uses a multi-stage build.

  • The first stage prepares the build environment (compiler and libraries).
  • The second one creates a bare image with only the program and its data.

Running the demo

From the Docker registry

docker run --rm -ti rene2/fromscratch

Nota: This image is made by the automated build system on Docker Hub's infrastructure.

With a fresh image

The demo.sh script builds and inspects the image (jq is required to filter the inspect output, or comment line 8).

Then, it runs the unique executable (a.out) in the container.

demo.png

To go further

Some explanations.

from-scratch's People

Contributors

rene-d avatar

Watchers

 avatar

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.