Helper script for use in an Alpine Docker image.
Replaces the default musl malloc implementation with mimalloc. If you build Rust or C/C++ static executables in an image using this script, the resulting executables will automatically link with mimalloc without needing any special build flags.
Supported & tested archs: amd64.
build.sh VERSION [SECURE]
- VERSION is your desired version of mimalloc.
- SECURE (optional) if mimalloc should be built with full security migitations (~10% slower)
RUN git clone "https://github.com/WebVOWL/rust-alpine-mimalloc"
WORKDIR /rust-alpine-mimalloc
# Build without secure mode
RUN /rust-alpine-mimalloc/build.sh 2.2.4
# Build with secure mode
# RUN /rust-alpine-mimalloc/build.sh 2.2.4 SECURE
# Set LD_PRELOAD to use mimalloc globally
ENV LD_PRELOAD=/usr/lib/libmimalloc.so
The script patches libc.a.
For more details, see
- the original blogpost.
- an offline copy of the original blogpost.