我想在Dockerfile
中交叉编译一个rust项目。我想在x86-64系统上运行docker buildx build -t my-image . --platform linux/arm64
,用Dockerfile
将Rust源代码复制到构建中并运行RUN cross build --target aarch64-unknown-linux-gnu --release
。我试过:
FROM --platform=linux/arm64 rust:1.68-slim as base
ENV CROSS_CONTAINER_IN_CONTAINER=true
RUN cargo install cross --git https://github.com/cross-rs/cross
WORKDIR /build
COPY . .
RUN rustup target add aarch64-unknown-linux-gnu
ENV CARGO_TARGET_DIR=/build
RUN cross build --target aarch64-unknown-linux-gnu --release
FROM debian:stable-slim
WORKDIR /app
COPY --from=base /build/my-app .
CMD ["./my-app"]
但我明白
=> ERROR [base 7/7] RUN cross build --target aarch64-unknown-linux-gnu --release 1.0s
------
> [base 7/7] RUN cross build --target aarch64-unknown-linux-gnu --release:
#0 0.903 Error:
#0 0.903 0: no container engine found
#0 0.903
#0 0.903 Suggestion: is docker or podman installed?
------
ERROR: failed to solve: executor failed running [/bin/sh -c cross build --target aarch64-unknown-linux-gnu --release]: exit code: 1
cross有在容器中运行的说明,但说明是在已经构建的容器中运行的,而不是在构建过程中。它们包括挂载主机的docker socket,但我不知道如何在运行docker buildx build ...
时挂载卷。
那么,如何交叉编译一个Rust项目与cross作为docker构建的一部分呢?
1条答案
按热度按时间1rhkuytd1#
安装docker CLI
RUN apt update && apt install -y docker.io
cross
在内部调用docker --help
来确定引擎类型,因此必须安装docker或podman二进制文件。