0

When I am using static-debian11 as the base image to run the rust app, shows error:

standard_init_linux.go:228: exec user process caused: no such file or directory

this is the main.rs:

fn main() {
    print!("hello world");
}

and this is the dockerfile:

# build stage
FROM rust:1.54-bullseye as builder
WORKDIR /app
COPY . /app
RUN rustup default stable
RUN cargo build --release
# RUN cargo build
# do not use slim image, will block when query database
FROM gcr.io/distroless/static-debian11
LABEL maintainer="jiang@gmail.com"
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
# ENV ROCKET_PORT=11014
COPY --from=builder /app/.env /app
COPY --from=builder /app/settings.toml /app

COPY --from=builder /app/target/release/alt-server /app/
CMD ["/app/alt-server"]

this is the cargo.toml:

[package]
name = "alt-server"
version = "0.1.0"
edition = "2021"

[dependencies]

I have already using the dive to check the docker image and make sure the /app/alt-server are exists. Am I missing something?

Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • Is the executable _completely_ statically-linked? Any attempt to use the dynamic linker at all and you'd expect this error, because `ld.so` is the "interpreter" used to run dynamic executables, much as something like python or bash is used as an interpreter to run a script; interpreter can't be found -> executable gives a "no such file or directory" during attempt. – Charles Duffy Jun 30 '23 at 16:54
  • 1
    ...see [How to generate statically linked executables](https://stackoverflow.com/questions/31770604/how-to-generate-statically-linked-executables) specifying the need to use `target-feature=+crt-static`. Also, [How to build a rust app free of shared libraries](https://stackoverflow.com/questions/59766239/how-to-build-a-rust-app-free-of-shared-libraries) – Charles Duffy Jun 30 '23 at 16:56
  • (If you want to confirm whether the above comments accurately reflect your problem, use `ldd` to inspect the `alt-server` executable) – Charles Duffy Jun 30 '23 at 16:57

0 Answers0