Compiling Static Binaries With Alpine

A static build is compiled version of a program which has been statically linked against libraries, according to Wikipedia. In practice, it means we can run a binary anywhere in compatible environments without installing dependencies. Although the binary is considerably larger, it greatly simplifies deployments. Learning by Example - cURL First, we take a look at how a static binary of cURL can be produced: 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 # dependencies to build curl apk add build-base clang openssl-dev nghttp2-dev nghttp2-static libssh2-dev libssh2-static # these are missing on at least armhf apk add openssl-libs-static zlib-static || true # gcc is apparantly incapable of building a static binary, even gcc -static helloworld.c ends up linked to libc, instead of solving, use clang export CC=clang # apply patches if needed #patch -p1 < ../static.patch #apk add autoconf automake libtool #autoreconf -fi # end apply patches # set up any required curl options here #LDFLAGS="-static" PKG_CONFIG="pkg-config --static" ./configure --disable-shared --enable-static --disable-libcurl-option --without-brotli --disable-manual --disable-unix-sockets --disable-dict --disable-file --disable-gopher --disable-imap --disable-smtp --disable-rtsp --disable-telnet --disable-tftp --disable-pop3 --without-zlib --disable-threaded-resolver --disable-ipv6 --disable-smb --disable-ntlm-wb --disable-tls-srp --disable-crypto-auth --without-ngtcp2 --without-nghttp2 --disable-ftp --disable-mqtt --disable-alt-svc --without-ssl LDFLAGS="-static" PKG_CONFIG="pkg-config --static" ./configure --disable-shared --enable-static --disable-ldap --enable-ipv6 --enable-unix-sockets --with-ssl --with-libssh2 make -j4 V=1 LDFLAGS="-static -all-static" This snippet is from Travis Burtrum’s static curl repository. There are several important points: ...

published on November 20, 2023 · last edited on October 28, 2026 · 6 min · 1210 words