skip to Main Content

I am a newbie trying to learn Docker. I am on WSL2 with Docker Desktop installed and running. I have a rust application that just runs a simple Actix web server. Here is my Dockerfile:

FROM rust:1.67

WORKDIR /usr/src/myapp
COPY . .

RUN cargo install --path .

CMD ["myapp"]

Everything works up until the last CMD command, which gives this error when I run the container:

docker run -it -p 8080:8080 --rm --name my-running-app my-rust-app
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "myapp": executable file not found in $PATH: unknown.

I understand the error – the container can’t find the rust executable for whatever reason.

I am out of ideas. Any help?

I have looked online for this issue and have tried the following:

  • changing CMD to ENTRYPOINT
  • running CMD ["./myapp"]
  • adding the executable to PATH with an ENV command

2

Answers


  1. Chosen as BEST ANSWER

    I don't know if this is a fix or not, but if it is relevant, I also have other binaries in the rust project (src/bin). I guess this makes a difference when running the cargo install command and not producing the executable. I changed the last line of the Dockerfile to CMD ["./target/release/<name>"], where <name> is the name of the project.


  2. Can you try passing the full path of the executable. You can get it by running cargo install --path . --list in your local Rust project directory.
    The output would be something like /usr/local/cargo/bin/myapp.
    Update the CMD instruction like CMD ["/usr/local/cargo/bin/myapp"].
    Rebuild the image and check if it works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search