100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
YAML

Installing and Using the Docker CLI

A practical guide to installing Docker and using its core CLI commands for pulling images, running containers, and inspecting Docker's state.

Containerization FundamentalsBeginner10 min readJul 8, 2026
Analogies

Installing and Using the Docker CLI

Before you can build or run containers, you need Docker installed and the docker command-line tool available in your shell. This section covers installation options and the core CLI commands you will use constantly: running containers, listing them, inspecting logs, and cleaning up resources.

🏏

Cricket analogy: Before you can play a match you need your kit bag packed and bat in hand; installing Docker and having the CLI ready is that essential prep before you can run, list, or inspect any 'innings' of containers.

Installation Options

On Linux, the recommended approach is Docker Engine installed directly from Docker's official APT or YUM repositories, giving you the daemon, CLI, and containerd as native services. On macOS and Windows, Docker Desktop provides a lightweight Linux VM (since both operating systems lack the Linux kernel features Docker needs) along with the daemon, CLI, and a GUI. Docker Desktop is also available for Linux as an alternative to a native Engine install.

🏏

Cricket analogy: Installing Docker Engine natively on Linux is like a home ground where the pitch (kernel) is already prepared; on foreign turf (macOS/Windows) you need to ship in a portable pitch (a lightweight Linux VM) via Docker Desktop first.

bash
# Install Docker Engine on Ubuntu/Debian (official convenience script, for evaluation)
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

# Verify the installation
$ docker --version
Docker version 25.0.3, build 4debf41

# Run the classic hello-world test container
$ docker run hello-world

The get-docker.sh convenience script is intended for testing and development environments, not production. For production servers, follow Docker's official package-manager installation instructions (apt/yum repositories) so you can control versions and receive updates through your normal patching process.

Running Your First Container

The docker run command creates and starts a container from an image in one step. Common flags include -d (detached, runs in the background), --name (assigns a friendly name), -p host:container (maps a host port to a container port), and -e KEY=value (sets an environment variable).

🏏

Cricket analogy: docker run is like sending a player onto the field in one motion: -d puts them on as a substitute working quietly (background), --name gives them a jersey number, -p maps the stadium gate to their position, and -e briefs them with match instructions.

bash
# Run an nginx web server in the background, named 'web', on host port 8080
$ docker run -d --name web -p 8080:80 nginx:1.25-alpine
c3f1a9e2d8b7...

# Confirm it's running
$ docker ps
CONTAINER ID   IMAGE                COMMAND                  STATUS         PORTS                  NAMES
c3f1a9e2d8b7   nginx:1.25-alpine    "/docker-entrypoint.…"   Up 3 seconds   0.0.0.0:8080->80/tcp   web

Once a container is running, you frequently need to check its logs, open a shell inside it, or view detailed configuration. The commands docker logs, docker exec, and docker inspect cover the vast majority of day-to-day debugging needs.

🏏

Cricket analogy: Checking a running container's logs, shell, and config is like reviewing a player's post-match footage (docker logs), talking to them directly in the dugout (docker exec), and reading their full performance report (docker inspect).

bash
# View recent logs, following new output
$ docker logs -f web

# Open an interactive shell inside the running container
$ docker exec -it web sh
/ # ls /usr/share/nginx/html
index.html
/ # exit

# Inspect detailed JSON configuration (IP address, mounts, env vars, etc.)
$ docker inspect web

Stopping a container with docker stop sends SIGTERM (then SIGKILL after a grace period) but does not delete it; the container still exists and can be restarted with docker start. docker rm permanently removes a stopped container. Because images, containers, networks, and volumes can accumulate over time, docker system prune is a common way to reclaim disk space.

🏏

Cricket analogy: docker stop is calling a batsman in for a break (SIGTERM, then forced off with SIGKILL) without retiring them from the squad; docker rm retires them permanently, and docker system prune clears out the old kit bags cluttering the dressing room.

bash
# Stop and remove the container
$ docker stop web
$ docker rm web

# Or do both in one step
$ docker rm -f web

# Remove unused images, stopped containers, and dangling networks
$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
Are you sure you want to continue? [y/N]
  • Docker Engine is the native install for Linux; Docker Desktop provides a VM-backed install for macOS and Windows.
  • docker run creates and starts a container in one command; common flags are -d, --name, -p, and -e.
  • docker ps lists running containers; add -a to include stopped ones.
  • docker logs, docker exec, and docker inspect are the core tools for debugging a running container.
  • docker stop halts a container gracefully; docker rm deletes it; docker rm -f does both.
  • docker system prune reclaims disk space by removing unused containers, networks, and dangling images.

Practice what you learned

Was this page helpful?

Topics covered

#YAML#DockerKubernetesStudyNotes#DevOps#InstallingAndUsingTheDockerCLI#Installing#Docker#CLI#Installation#StudyNotes#SkillVeris