Run under docker without compilation no such a file or directory


I try to run a docker image where the code is not compiled inside docker, but compiled in the host computer (Ubuntu 20).

FROM alpine
COPY target/debug/permutation_web_server .
RUN ls -lisa
ENTRYPOINT ["./permutation_web_server"]

Here is the build command line :

$ docker build -t permutation_web_server .
Sending build context to Docker daemon  1.291GB
Step 1/5 : FROM alpine
 ---> c059bfaa849c
Step 2/5 : WORKDIR /app
 ---> Using cache
 ---> 1f824eedcee1
Step 3/5 : COPY target/debug/permutation_web_server .
 ---> Using cache
 ---> 55ac0784c4e3
Step 4/5 : RUN ls -lisa
 ---> Running in a269ba690edc
total 103844
10095543      4 drwxr-xr-x    1 root     root          4096 Feb 12 13:33 .
12582960      4 drwxr-xr-x    1 root     root          4096 Feb 12 17:21 ..
10095544 103836 -rwxrwxr-x    1 root     root     106325704 Feb 12 00:45 permutation_web_server
Removing intermediate container a269ba690edc
 ---> 23b2844b7f1a
Step 5/5 : ENTRYPOINT ["./permutation_web_server"]
 ---> Running in f7778e674429
Removing intermediate container f7778e674429
 ---> 3751b71fb7b5
Successfully built 3751b71fb7b5
Successfully tagged permutation_web_server:latest

and the run command line where it fails :

docker run -p 8080:8080 permutation_web_server
standard_init_linux.go:228: exec user process caused: no such file or directory

Please advise

Thank you

Ubuntu and Alpine use different C library. Therefore, do not use Alpine.

You need to compile your binary with --target=x86_64-unknown-linux-musl

For that purpose you either need to have musl libraries installed or you can use rust docker image for alpine
Even official docker images provide you with alpine version Image Layer Details - rust:alpine3.15 | Docker Hub which you can use to compile your binary.

Also do not listen to @sanxiyn Alpine is preferable for deployment due to its small size, so I would advice to investigate tooling for musl cross-compilation (in your case docker is already providing you with it)

There is also tool cross-rs/cross: “Zero setup” cross compilation and “cross testing” of Rust crates ( for more advanced builds which handles nasty things like OpenSSL for you

you can use rust docker image for alpine

OP clearly stated "code is not compiled inside docker", so I don't think this is a useful advice.

Yes, you can try to cross compile to use musl C library, but if you compile on Ubuntu, running on Ubuntu would cause the least amount of hassle. You can investigate size optimization later once it works.

Thank you @DoumanAsh compiling with --target=x86_64-unknown-linux-musl made it worked.

Moreover, I had to change the binding of the webserver from to

@sanxiyn what is the issue about size optimisation ?

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.