-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerize Rust Server for Production #8
Comments
5-pebbles
added a commit
that referenced
this issue
May 2, 2024
Closes #8 Everything should now work in a docker container. Added a release profile to the `Rocket.toml` so it listens on the external IP of the container to allow port forwarding. I documented everything else in the dockerfile so here it is: ```Dockerfile # First Stage FROM rust:alpine as build WORKDIR /src # ca-certificates so we can copy /etc/ssl to the release stage RUN apk update && apk add --no-cache \ ca-certificates \ build-base \ pkgconfig \ libressl-dev \ musl-dev \ perl RUN rustup target add x86_64-unknown-linux-musl # Build & Cache Dependencies RUN USER=root cargo new tuna WORKDIR /src/tuna COPY Cargo.toml Cargo.lock ./ RUN cargo build --target x86_64-unknown-linux-musl --release # Build the App COPY ./src ./src # Refinery embeds the migrations at build time COPY ./migrations ./migrations # Cargo checks if it needs to rebuild based on the mtime of the files... # The copied main.rs retains the original timestamp, so the dummy looks newer -_- RUN touch src/main.rs # It was consensual I swear! RUN cargo build --target x86_64-unknown-linux-musl --release # Second Stage FROM scratch as release # We can use the ssl certs from the build stage COPY --from=build /etc/ssl /etc/ssl # Copy the binary from build stage COPY --from=build /src/tuna/target/x86_64-unknown-linux-musl/release/tuna . # Runtime config files COPY ./Rocket.toml /Rocket.toml # blast off CMD ["/tuna"] # Notes: # - rusqlite has a feature bundled which automatically compiles and links SQLite. # - you need to add volumes for the database directory or the data won't be persistent. ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I can just make a two-stage Docker build.
I can compile in a
rust:alpine
image (alpine will ensure dependencies are statically linked) then copy the binary to ascratch
image.The only issue (yah right) might be the ssl certs but I can just copy all of
/etc/ssl
from thebuild
image to therelease
image.Its a few extra kilobytes but I don't think that's an issue...
The text was updated successfully, but these errors were encountered: