DEV Community

özkan pakdil
özkan pakdil

Posted on • Originally published at ozkanpakdil.github.io on

How to containerize a rust warp app

I wrote this arti warp server for running whois via TOR network, Arti is CLI tool which has arti_client library inside for connecting the network, my main target to dockerize this for easy deploy to koyeb.com

  1. I used docker init to create Dockerfile and others and changed the implementation little bit because of some special dependencies
ARG RUST_VERSION=1.82.0
ARG APP_NAME=arti_whois

FROM rust:${RUST_VERSION}-alpine AS build
ARG APP_NAME
WORKDIR /app

# Install host build dependencies.
RUN apk add --no-cache clang lld musl-dev git openssl-dev openssl libssl3 libcrypto3 libgcrypt openssl-libs-static ca-certificates

RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry/ \
cargo build --locked --release && \
cp ./target/release/$APP_NAME /bin/server

FROM alpine:3.18 AS final

USER root
COPY --from=build /bin/server /bin/

EXPOSE 8016

ENV RUST_BACKTRACE=1
ENV RUST_LOG=debug

CMD ["/bin/server"]

Enter fullscreen mode Exit fullscreen mode

apk add part took a while to figure out because on every run, compile was failing with different error, I needed to install all the dev lib dependencies to the alpine linux

  1. Test with docker compose up --build until everything is fine. I was using curl for testing the app curl "localhost:8016/whois?ip=1.1.1.1" -v
  2. Than docker push ozkanpakdil/arti_whois to push it to docker repository

Now the app is in the docker hub 🥳

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay