✦ For everyone, free.

Practical knowledge for real and everyday life

Home

2.1.2.1 Client CLI Interaction

A focused guide to Client CLI Interaction, connecting core concepts with practical Docker and container operations.

Client CLI interaction is the everyday experience of typing docker commands at a terminal and seeing them carried out — the command-line interface translating human-readable subcommands and flags into the precise API calls the daemon understands.

Command Structure

Docker's CLI follows a consistent pattern of a top-level command, a subcommand, and flags or arguments specific to that subcommand, making the command line predictable once the pattern is familiar.

docker <command> <subcommand> [options] [arguments]
docker container run -d --name myapp myapp:1.0
docker image build -t myapp:1.0 .

Many commands also have shorter aliases that omit the resource type, since it can be inferred from context.

docker run -d --name myapp myapp:1.0
docker build -t myapp:1.0 .
Interactive vs. Detached Execution

The CLI supports both running a container interactively, attaching the terminal directly to the container's input and output, and running it detached, returning control to the terminal immediately while the container continues in the background.

docker run -it ubuntu:22.04 bash
docker run -d nginx
Streaming Output From Running Containers

Because containers can run for a long time, the CLI provides commands to stream a container's logs or attach to its output after it has already started, without needing to have been present when it was first run.

docker logs -f myapp
docker attach myapp
Executing Commands Inside a Running Container

The CLI can also run an additional command inside an already-running container, which is commonly used for inspection or debugging without disturbing the container's main process.

docker exec -it myapp sh
Why a Consistent CLI Matters

Because every Docker subcommand follows the same general structure and ultimately maps to the same underlying API, learning the CLI's conventions once makes the entire surface of Docker's functionality accessible, rather than requiring separate conventions to be learned for managing images, containers, networks, and volumes individually.