Small and secure Docker images for Rust: Alpine vs Debian vs Scratch

17 days ago by Ephera to c/rust

While Docker is now the main way to distribute backend software and CLI tools, you may be wondering how to build minimal and secure Docker images for your Rust projects.

Was recently somewhat surprised that you can't just copy a Rust executable into a ´scratch´ container and have it work, so this is a cool blog post to find in my RSS feed.

I'm guessing, if you're doing something less complex, then you just need the ´musl´ target and the allocator...

load all comments
jldevezas 3 points 17 days ago

Personally, I settled on wolfi-base, which feels a lot like Alpine, but is based on glibc, so there's fewer compatibility issues. I also considered debian-slim, but there's just too many CVEs in Debian, and I was fed up with it being so outdated all the time. What I really wanted was something like wolfi, but more open, i.e., not associated with paid images. We need a glibc-based Alpine!

path: 0 26030330, hotness: undefined, score: 3, children: 2
davel 3 points 17 days ago

Thanks, I hadn't heard of Wolfi, nor of Chainguard. They are by a for-profit company, which isn’t an automatic deal-breaker by any means—it could even be a net-positive—but I do have some more homework to do before jumping onboard.

path: 0 26030330 26032470, hotness: undefined, score: 3, children: 1
jldevezas 3 points 17 days ago

Because most images from Chainguard are paid, apart from the base image, the way I use it is through multi-stage builds, where I simply copy what I need from other images into the wolfi base, unless of course it's just easier to install what I want using apk. If I could do that with plain Alpine, I would, but most stuff is compiled for glibc, so it's a no-go.

If security is the main factor for your, I'd recommend you scan the image with grype, so you can get a grasp of how many CVEs you're working with.

path: 0 26030330 26032470 26042075, hotness: undefined, score: 3, children: 0
rust
rust

@lemmy.ml

login for more options
9397
397
129

go to feed...