LoginSignup
1
0

More than 1 year has passed since last update.

RustでDistrolessのdocker imageを作成する

Posted at

概要

RustアプリケーションをKubernetes上で動かすことを想定し、
DistrolessでのDocker imageを作成する手順を記載します。

参照

Rustアプリケーションを作成

% cargo new distroless_hello_world
     Created binary (application) `distroless_hello_world` package
% cd distroless_hello_world   
% cargo run                                                                              
   Compiling distroless_hello_world v0.1.0 (/.../distroless_hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 4.30s
     Running `target/debug/distroless_hello_world`
Hello, world!

Dockerfileを作成

FROM rust:1.61.0-bullseye as build-env
WORKDIR /app
COPY . /app
RUN cargo build --release

FROM gcr.io/distroless/cc
COPY --from=build-env /app/target/release/distroless_hello_world /
CMD ["/distroless_hello_world"]

動作確認

% docker build .
 ...
 => => writing image sha256:1adba3574ed863f3ba829eff0f4e817def15bf7dc313e689cc5b3b22caf8aabb

% docker image inspect -f "{{ .Size }}" 1adba3574ed863f3ba829eff0f4e817def15bf7dc313e689cc5b3b22caf8aabb | numfmt --to=si 
27M

% docker run 1adba3574ed863f3ba829eff0f4e817def15bf7dc313e689cc5b3b22caf8aabb            (git)-[master]-[~/src/github.com/takisawa/rust-study/distroless_hello_world]
Hello, world!
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0