DEV Community

Discussion on: First steps with Docker + Rust

Collapse
 
tomasfejfar profile image
Tomáš Fejfar

When running

RUN cargo build --release
RUN rm src/*.rs
Enter fullscreen mode Exit fullscreen mode

if you ran

RUN cargo build --release & rm src/*.rs
Enter fullscreen mode Exit fullscreen mode

you'd actually get smaller and cleaner layer as the rs files in src would not be part of it. By separating to two different layers you actually create one layer with deps+rs files and another layer that removes the rs files IMHO.

Collapse
 
tahacoder43 profile image
Taha Munawar

You have to use "&&" instead of "&", if you use a single & then the rm command would run before cargo builds, additionally you can remove this line too

RUN rm ./target/release/deps/holodeck*
Enter fullscreen mode Exit fullscreen mode

and change that previous line too

RUN cargo build --release && rm src/*.rs && rm ./target/release/deps/holodeck*
Enter fullscreen mode Exit fullscreen mode