docker-rust icon indicating copy to clipboard operation
docker-rust copied to clipboard

Alpine missing libc-dev

Open misalcedo opened this issue 4 years ago • 5 comments

I tried building executables using the alpine latest and the build failed unless I added RUN apk add libc-dev to my builder image. See https://github.com/misalcedo/kv-store for a sample repo that fails to build. Another one of my repos also failed.

The basic hello-world crate does build in this base image.

Looking at the debian-based images we do install libc-dev there. Is there any reason not to include it for Alpine?

I am new to compiling Rust with MUSL, so there may very well be a better way to do this.

misalcedo avatar Dec 24 '21 12:12 misalcedo

The Alpine images are significantly more minimal than the standard Debian images - the slim Debian images are a better reference. libc-dev is only required when building C code as part of the compilation process.

sfackler avatar Dec 24 '21 17:12 sfackler

It's good to know that it's a conscious choice to keep the alpine image size down. Would be good to document that somewhere though. Took me a long time to figure out why the builds were broken as most rust alpine examples don't seem to compile c code so I didn't have much reference material to borrow from.

Granted this is my first time trying to create a scratch image from Rust, but if it's a common use case others may have the same problem.

misalcedo avatar Dec 24 '21 22:12 misalcedo

The Alpine images are significantly more minimal than the standard Debian images - the slim Debian images are a better reference. libc-dev is only required when building C code as part of the compilation process.

Why? I mean, I want to discuss real foundation of this choice. I bring two use cases as examples.

I use rust:1.75-alpine3.19 to build an executable:

FROM rust:1.75-alpine3.19

RUN cargo build --release

RUN mv target/release/myapp /myapp

FROM scratch as distro

COPY --from=builder /myapp /myapp

build and tag it with myapp:v0.1-alpine

From another image define

FROM myapp:v0.1-alpine as builder
## just be sure is there
RUN ls /myapp

FROM alpine:latest

COPY --from=builder /myapp /usr/local/bin/myapp
## etc

A second use case is to build inside the first of 2-stage Dockerfile directly. Ending with a slim image anyway.

What I am asking is: there are other real scenario in use? Who is using the rust image for something else than "compile-then-move-away"?

An image supposed to be useful for building rust code currently misses also the musl-dev package, and it is building for a musl architecture.

How much minimal should be? (or should it be really minimal at all?)

danielecr avatar Feb 06 '24 07:02 danielecr

just want to drop my opinion here- yeah, i don't think it being minimal makes sense. rustc is huge.

randomairborne avatar Feb 20 '24 07:02 randomairborne

just want to drop my opinion here- yeah, i don't think it being minimal makes sense. rustc is huge.

yep, I see your point. My comments was meaningless. Sorry.

danielecr avatar Jul 02 '24 17:07 danielecr