1

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.

Ryan Callahan
  • 115
  • 1
  • 11
  • 2
    You can't combine the images (see [Is there a way to combine Docker images into 1 container?](https://stackoverflow.com/questions/39626579/is-there-a-way-to-combine-docker-images-into-1-container)). Your first Dockerfile uses a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/) so the final image doesn't contain the Rust toolchain; if you use APT to install the dependencies in the build stage, they won't appear in the final image. – David Maze May 05 '21 at 03:27
  • 1
    You are also installing vastly more than just gstreamer into your builder: find out what you really need to build and install just those packages. – Jussi Kukkonen May 05 '21 at 07:27

0 Answers0