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

























