Skip to content

Instantly share code, notes, and snippets.

@xarantolus
Created December 10, 2023 10:31
Show Gist options
  • Save xarantolus/6202b3a5013deeabd3d502a4a9fdc2da to your computer and use it in GitHub Desktop.
Save xarantolus/6202b3a5013deeabd3d502a4a9fdc2da to your computer and use it in GitHub Desktop.
Dockerfile for cross-compiling a Rust project for ARM64. I use this to build ARM64 containers for my Raspberry Pi 4 on an x86 machine
FROM rust:1.74-slim-buster as builder
RUN rustup target add aarch64-unknown-linux-gnu
RUN apt-get update && \
apt-get install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
# Copy project into container
COPY . .
RUN cargo build --target aarch64-unknown-linux-gnu --release
# Final Stage
FROM arm64v8/debian:buster-slim
COPY --from=builder /target/aarch64-unknown-linux-gnu/release/<my-executable> /<my-executable>
# env_logger setting
ENV RUST_LOG=info
CMD ["/<my-executable>"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment