To create a slim rust docker image, one needs to do the following with below assumptions
- The project would generate a binary tool called
ims2_tool
- Its version is annotated in clap derive API, so the script could fetch the version directly from source code.
- Create a multi-stage docker file, see Dockerfile
- Modify your project's
Cargo.toml
file so desired[[bin]]
section must exist, otherwise docker build would fail duringcargo prepare
phase.
[[bin]]
name="<executable name>"
bench=false
test=false
- Create a build_docker.sh to update your image easily.