liveBook · Manning

Docker

As explained in Rust Servers, Services, and Apps

Docker is a platform and toolset for building, packaging, and running applications in containers.

Docker packages applications, services, and databases into containers, reducing friction between development and operations. Dockerfiles define images; containers instantiated from those images run the application and service requests. section 1.3 section 12.6

A practical Docker workflow includes:

  • Create a Rust web service, verify it with cargo run, then define its image in a Dockerfile. section 12.2.2
  • Build and inspect the image, run it with a published port, and test the same endpoints inside the container. section 12.2.2
  • Reduce image size with static musl binaries and multistage builds that discard compilers and intermediate artifacts. section 12.6
  • Coordinate several containers with Docker Compose, custom networks, and volumes for persistent data. section 12.6

Containerizing a Rust web service

A Dockerfile can start from the Rust image, copy the project into /app, build with cargo build --release, and launch ./target/release/docker-rust. Build it with docker build -f Dockerfile-basic . -t docker-rust-basic, then run it with docker run -p 8080:8080 -t docker-rust-basic and test localhost:8080 and localhost:8080/hello. The initial image is 1.32 GB because it retains the compiler, dependencies, and build artifacts. section 12.2.2

cargo new --bin docker-rust
cd docker-rust

Start the runnable project with cargo new --bin docker-rust and cd docker-rust before adding the web service and Dockerfile. section 12.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Builds and runs a basic image, then extends the treatment to multistage builds, static binaries, Compose, networks, and volumes.
Examples
Uses an Actix Web service with root and /hello endpoints, a Dockerfile-basic image, Docker CLI commands, and browser tests.
What it assumes
Assumes a working Rust web service and introduces container packaging through a concrete deployment workflow.
What you can do after
Operate/configure Docker to build images, run Rust services, test published endpoints, and coordinate containers with Compose.
How it connects
Connects Dockerfiles, Docker Compose, static binaries, musl, container networks, and persistent volumes.

Also explained in

Compare how 26 books explain Docker →

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.