我正在尝试运行这个Docker镜像,我是Docker世界的新手。感谢帮助:(我正在尝试在谷歌云上使用Docker使用postgres运行一个简单的Rust微服务。但是在构建完成后,就不能复制二进制文件了
Cargo.toml:
[package]
name = "home_made_rust"
version = "0.1.0"
edition = "2018"
[dependencies]
postgres = "0.17.5"
下面是我的Dockerfile
# ------------------------------------------------------------------------------
# Cargo Build Stage
# ------------------------------------------------------------------------------
FROM rust:latest as builder
WORKDIR /rust
# Download the cargo target
RUN rustup target add x86_64-unknown-linux-musl
# create dummy application, s.t. cargo can download all dependencies
RUN mkdir -p /rust/app/src && echo 'fn main(){}' > app/src/main.rs
WORKDIR /rust/app
# Build & cache dependencies
COPY Cargo.toml Cargo.lock ./
RUN cargo build --release --target x86_64-unknown-linux-musl
# Copy application code
COPY src ./src
# Build production binary
RUN touch src/main.rs && cargo build --release --target x86_64-unknown-linux-musl
# Production container
FROM scratch
COPY --from=builder /rust/app/target/x86_64-unknown-linux-musl/release/microservice_app /app
ENTRYPOINT ["/app"]
这是我的Rust项目结构
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-07-2020 07.36 PM .github
d----- 30-07-2020 07.24 PM src
d----- 30-07-2020 07.25 PM target
-a---- 30-07-2020 11.44 PM 19 .dockerignore
-a---- 30-07-2020 07.24 PM 8 .gitignore
-a---- 30-07-2020 10.58 PM 20573 Cargo.lock
-a---- 30-07-2020 10.58 PM 250 Cargo.toml
-a---- 31-07-2020 10.31 AM 974 Dockerfile
github操作的确切错误->
Step 11/12 : COPY --from=builder /rust/app/target/x86_64-unknown-linux-musl/release/microservice_app /app
COPY failed: stat /var/lib/docker/overlay2/912bcbdb9b9198001ae5d1df4aec09ec54efb413fbb8981d165ee529ea9966a6/merged/rust/app/target/x86_64-unknown-linux-musl/release/microservice_app: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
替换此COPY --from=builder /rust/app/target/x86_64-unknown-linux-musl/release/microservice_app /app
其中这=>
COPY --from=builder /rust/app/target/x86_64-unknown-linux-musl/release/home_made_rust /app
二进制名称按照Cargo.toml文件
[package]
name = "home_made_rust"