
- Rust toolchain (rustup + cargo)
- Docker running locally (Docker Desktop on macOS/Windows or Docker daemon on Linux)
- Basic familiarity with async/await in Rust
- Optional: VS Code (or your preferred editor)

Project structure
We will keep the code modular:
- src/cli.rs — Clap definitions (commands/subcommands)
- src/docker.rs — DockerClient wrapper around Bollard
- src/main.rs — Top-level wiring and command dispatch
- mydocker list containers [—all | -a]
- mydocker list images
- mydocker start <container_name>
- mydocker stop <container_name>
- mydocker pull <image_name>
Ensure Docker is running (Docker Desktop or a daemon on Linux). The typical Docker socket path on Linux is /var/run/docker.sock. On Docker Desktop (macOS/Windows) the socket path may differ — use
docker context inspect to find the “Host” value and adjust the socket path in DockerClient::new if needed.
Run & test examples
- Show general help:
- List running containers:
- List all containers, including stopped:
- List images:
- Start a container:
- Stop a container:
- Pull an image:
- Docker returns many optional fields (names, status, IDs). The example code uses unwrap_or_default() to avoid panics and print reasonable defaults.
- Bollard’s create_image returns a stream of progress messages — the client consumes and prints these lines to provide visible progress.
- If a resource does not exist, Docker returns an error (often a 404-like response). The CLI forwards the error message returned by the Docker daemon to stderr.
If you use a Unix socket (e.g., /var/run/docker.sock) your user needs permission to access that socket (membership in the docker group, or run the binary with appropriate privileges). On macOS/Windows with Docker Desktop, the socket path may differ — use
docker context inspect to find the socket path and adjust DockerClient::new accordingly.- container inspect, remove, exec
- filtering lists by labels, status, or health
- richer output formatting (JSON, table)
- authentication support for pulling from private registries
- Built a small Rust CLI (mydocker) using Clap for argument parsing and Bollard for Docker API access.
- Organized code into src/cli.rs, src/docker.rs, and src/main.rs for clarity and maintainability.
- Implemented list (containers/images), start, stop, and pull commands with async/await using Tokio.
- The project is a solid foundation to grow into a full-featured Docker management tool in Rust.
- Bollard (Docker client for Rust): https://docs.rs/bollard/
- Clap (CLI parsing): https://clap.rs/
- Tokio (async runtime): https://tokio.rs/
- Docker documentation: https://docs.docker.com/