Running Rust Microservice using Docker, not able to copy the binary

I'm trying to Run a simple Rust microservice with postgres using Docker on Google Cloud. But After build is finished, it is not able to copy the binary.

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"]

This is the exact Error:

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

fixed here.

COPY        --from=builder /rust/app/target/x86_64-unknown-linux-musl/release/home_made_rust /app

binary name is as per Cargo.toml file

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.