I have a rust service that is dependent on gstreamer and I would like to containerize it. There exists a rust image with debian and a gstreamer image with ubuntu on docker hub. I am still new to creating docker files so I'm not sure what the correct way to go about this is.
This is what I got from following along this log rocket article: https://blog.logrocket.com/packaging-a-rust-web-service-using-docker/. I modified it a bit to what my needs were.
FROM rust:1.51.0 as builder
RUN USER=root cargo new --bin ahps
WORKDIR /ahps
RUN touch ./src/lib.rs
RUN mv ./src/main.rs ./src/bin.rs
COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --release
RUN rm -r src/*
ADD . ./
RUN rm ./target/release/deps/ahps*
RUN cargo build --release
FROM restreamio/gstreamer:latest-prod
ARG APP=/usr/src/ahps
COPY --from=builder /ahps/target/release/ahps ${APP}/ahps
WORKDIR ${APP}
CMD ["./ahps"]
This doesn't work because the rust build depends on gstreamer. I was able to get a working file by using apt-get to install gstreamer on top of the rust image, but the size went from ~700MB to 2.6GB due to the gstreamer image being much more optimized. This is the docker file that makes a 2.6gb image:
FROM rust:1.51.0
RUN apt-get update
RUN apt-get -y install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
WORKDIR /ahps
COPY . .
RUN cargo build --release
WORKDIR /ahps/target/release
CMD ["./ahps"]
Overall I'm looking for a way to utilize both images where the gstreamer one is a dependency for my rust build. Thanks in advance.