liveBook · Manning

Containerization

As explained in Rust Servers, Services, and Apps

Containerization packages an application and its dependencies into isolated, portable runtime units called containers.

Containerization packages an application and its dependencies into an isolated, portable runtime unit. Docker containers isolate processes, networking, and volumes while sharing the host operating system kernel, unlike virtual machines that include complete operating systems. section 12.0 section 12.1.2

A practical containerization workflow builds and validates a Rust web service incrementally:

  • Create an Actix Web service, run it with cargo run, and test its endpoints at localhost:8080. section 12.2.2
  • Define a Dockerfile that selects a Rust image, copies the project, builds a release binary, and starts it with CMD. section 12.2.2
  • Build the image with docker build, inspect it with docker images, and run it with port 8080 published. section 12.2.2
  • Compare the containerized service with the locally run version, then reduce the initial image size when production efficiency matters. section 12.2.2

Containerizing a Rust web service

A small Actix Web application exposes / and /hello on port 8080. A basic Dockerfile uses FROM rust, copies the project into /app, runs cargo build --release, and starts ./target/release/docker-rust. Building with docker build -f Dockerfile-basic . -t docker-rust-basic produces a runnable image; docker run -p 8080:8080 -t docker-rust-basic serves the same endpoints. The first image is intentionally large—1.32 GB—because it retains the compiler and intermediate build artifacts. section 12.2.2

Figure 12.2 Docker overview

Use the Docker overview to visualize how containers sit above hardware infrastructure and share the operating system kernel. section 12.1.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Progresses from isolation concepts to a working Dockerfile, image build, container execution, endpoint testing, and image-size concerns.
Examples
Uses an Actix Web service, Dockerfile-basic, Docker build and run commands, localhost endpoints, and a 1.32-GB image.
What it assumes
Assumes an existing Rust web service and local development workflow, while introducing Docker packaging from the first container onward.
What you can do after
Builds and runs a Docker container for a Rust web service, then tests its published HTTP endpoints.
How it connects
Links Docker, Docker Compose, Rust, Actix Web, virtual machines, operating system kernels, and production deployment.

Also explained in

Compare how 2 books explain containerization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.