gema-arta / docker-build-python-static-bin

Docker image that allows to build static binaries for Python applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build a static binary from a Python script

The Docker image available on this repository allows to build Linux static binaries from python scripts/applications. This binaries should run fine on any Linux system (x64 only).

The binary is built using Nuitka together with a Python 3.10 static build.

The build logic was adapted from https://github.com/xxh/xxh .

How to use this repository (from source)

Create the docker image

docker build . -t build-python-bin

Create a hello world script (test.py)

print("Hello world from static python")

Create the static binary

docker run --user $(id -u) -v $(pwd):/build -it build-python-bin test.py

# Resulting binary will be at test.dist/test, rename, check and cleanup
mv test.dist/test my_static_binary
file my_static_binary
rm -rf test.dist/

Test it in some docker images (not containing Python):

docker run -v $(pwd):/tmp -it alpine /tmp/my_static_binary
docker run -v $(pwd):/tmp -it debian /tmp/my_static_binary
docker run -v $(pwd):/tmp -it ubuntu /tmp/my_static_binary

About

Docker image that allows to build static binaries for Python applications

License:MIT License


Languages

Language:Dockerfile 73.0%Language:Shell 23.4%Language:Python 3.6%