1

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?

user1445685
  • 793
  • 1
  • 11
  • 25
  • Hmm I am unable to reproduce your issue. Can you edit it with a description of what the entire directory looks like? And possibly the contents of `Cargo.toml`? – opeonikute Sep 02 '23 at 08:58
  • I edited the question with the cargo file – user1445685 Sep 02 '23 at 09:13
  • Hm that still works for me. I previously had an answer that said you should try using the full path in `CMD ["/home/appuser/backend"]`, but deleted because the relative path worked for me – opeonikute Sep 02 '23 at 09:30
  • Ok. Let me start from scratch on a fresh new project and I'll let you know. Thank you for your time – user1445685 Sep 02 '23 at 09:33
  • So the fresh new project worked as it's supposed to... – user1445685 Sep 02 '23 at 09:47
  • So I destroyed the instance, and tried again. The error changed. Now I get ./backend: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory – user1445685 Sep 02 '23 at 09:58
  • solved it by using debian:bullseye-slim as runner – user1445685 Sep 02 '23 at 10:16

1 Answers1

2

Issue due maybe to so caching issue. Solved the libssl.so.1.1: issue by using debian:bullseye-slim as runner.

user1445685
  • 793
  • 1
  • 11
  • 25