I try to run a docker image where the code is not compiled inside docker, but compiled in the host computer (Ubuntu 20).
COPY target/debug/permutation_web_server .
RUN ls -lisa
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
Step 2/5 : WORKDIR /app
---> Using cache
Step 3/5 : COPY target/debug/permutation_web_server .
---> Using cache
Step 4/5 : RUN ls -lisa
---> Running in a269ba690edc
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
Step 5/5 : ENTRYPOINT ["./permutation_web_server"]
---> Running in f7778e674429
Removing intermediate container f7778e674429
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
Ubuntu and Alpine use different C library. Therefore, do not use Alpine.
You need to compile your binary with
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 (github.com) 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
@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.