FROM rust:latest as build # FROM rust:1.50 as builder # Use prebuilt builder image # FROM rust:1.50-prebuilt as builder # RUN rustup target add x86_64-unknown-linux-musl # RUN apt-get update && apt-get install -y musl-tools # 使用 sed 修改 Rust 源为 163 的镜像源 # RUN sed -i 's#https://mirrors.ustc.edu.cn/rust-static#https://mirrors.163.com/crates-io#g' /usr/local/cargo/config # 设置 Rust 默认工具链版本 ENV RUST_VERSION=nightly RUN mkdir app # 设置工作目录 WORKDIR /app # 申明变量 APP 并赋值 ARG APP=fache RUN echo '打印变量' $APP # 复制 COPY README.md ./ COPY Cargo.toml ./ COPY ./src src # COPY Cargo.lock ./ # 安装 # RUN cargo install # RUN cargo install --path . --color always # 打印版本 RUN rustc --version # 打印版本 RUN cargo build # RUN cargo build --target=x86_64-unknown-linux-musl --release # 登录 cargo 后台 RUN cargo login ciobQdIbkHwTmTBq2fxxDmnRl5HqEzTaGFA # 推送到后台 RUN cargo publish --allow-dirty # 切换容器运行的用户 # USER 1000 # ENTRYPOINT ["/$APP"] # 启动应用程序 # CMD ["cargo", "run"]