I'm on a M2 Mac trying to build a docker image for my Rust api. The image is pushed to a registry and run on an linux/amd64 instance on scaleway. Here is my dockerfile:
# Build stage
FROM --platform=linux/amd64 rust:1.72-buster as builder
RUN rustup update
# Install dependencies
RUN apt-get update && apt-get install -y \
libpq-dev \
libssl-dev
# Create a new user for the application
RUN useradd --create-home appuser
# Set the working directory for the rest of the commands
WORKDIR /home/appuser
# Copy the application source code
COPY . .
# Build the application
RUN cargo build --release
# Runtime stage
FROM --platform=linux/amd64 debian:bookworm-20230814-slim as runner
# Install dependencies
RUN apt-get update && apt-get install -y \
libpq5 \
libssl3
# Create a new user for the application
RUN useradd --create-home appuser
# Set the working directory for the rest of the commands
WORKDIR /home/appuser
# Copy the compiled binary from the build stage
COPY --from=builder /home/appuser/target/release/backend .
# RUN ping 0.0.0.0
# Set the user to appuser
USER appuser
RUN ls -al
EXPOSE 8880
# Run the application
# CMD ["./backend"]
I build the image with the following command:
docker buildx build --platform linux/amd64 --output type=docker -t backend-api .
When I run it I have the following error
exec ./backend: no such file or directory
But when I enter the image and run ls -al, the file is listed.
The cargofile:
[package]
name = "backend"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
juniper = "0.15.10"
actix-web-lab = "0.18"
actix-cors = "0.6"
serde_json = "*"
serde = { version = "1.0", features = ["derive"] }
reqwest = {version = "0.11.13", features = ["json"]}
anyhow = "1.0.66"
jwt = "0.16.0"
hmac = "0.12.1"
sha2 = "0.10.6"
jsonwebtoken = "8.2.0"
env_logger = "0.10.0"
[profile.release]
opt-level = 'z' # Optimize for size.
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = 'abort' # Abort on panic
strip = true # Strip symbols from binary*
What I'm I doing wrong?