Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Installation and Basics Docker CLI Overview docker help
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-installation-and-basics-docker-cli-overview-docker-help

Docker Docker Installation and Basics Docker CLI Overview docker help

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

This topic provides an overview of the Docker CLI and its usage. docker --help.

2. Step-by-Step

  1. Open a terminal and check if Docker is installed by running docker --version.
  2. Run docker --help to see the full list of available commands and flags.
  3. Look for the docker run command and note its usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...].
  4. Run docker run -it ubuntu /bin/bash to start a new container from the Ubuntu image and open a bash shell.
  5. ⚠️ Run docker ps -a to list all containers, including stopped ones.
  6. Run docker stop <container_id> to stop a running container.
  7. ⚠️ Run docker rm -f <container_id> to delete a stopped container.
  8. Run docker rmi <image_id> to delete an unused image.

3. Real Commands with Examples


Example 1: Run a Container

  • Purpose: Run a new container from a Docker image.
  • Command: docker run -it ubuntu /bin/bash
  • Brief explanation of flags: -it flag allows interactive shell, ubuntu is the image name, /bin/bash is the command to run.

Example 2: List Containers

  • Purpose: List all running and stopped containers.
  • Command: docker ps -a
  • Brief explanation of flags: -a flag lists all containers, not just running ones.

Example 3: Delete Unused Images

  • Purpose: Delete unused Docker images.
  • Command: docker rmi $(docker images -q -f dangling=true)
  • Brief explanation of flags: -q flag shows only image IDs, -f dangling=true filters for unused images.

4. Common Errors


Error 1: Unable to Run Container

  • Error message or symptom: docker: Error response from daemon: ....
  • Why it happens: Docker daemon is not running or not accessible.
  • One-line fix: sudo systemctl start docker (on Linux) or dockerd --log-driver=none (on Windows).

Error 2: Image Not Found

  • Error message or symptom: docker: Error response from daemon: ....
  • Why it happens: Docker image is not available or not pulled.
  • One-line fix: docker pull <image_name>.

Error 3: Container Not Found

  • Error message or symptom: docker: Error response from daemon: ....
  • Why it happens: Container is not running or not accessible.
  • One-line fix: docker start <container_id>.

5. Quick Checks


Scenario 1: Check Docker Version

  • Situation: You want to check the Docker version.
  • Command: docker --version
  • What a correct response looks like: Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2

Scenario 2: Check Running Containers

  • Situation: You want to check if a container is running.
  • Command: docker ps
  • What a correct response looks like: A list of running containers with their IDs and names.

Scenario 3: Check Docker Images

  • Situation: You want to check if a Docker image is available.
  • Command: docker images
  • What a correct response looks like: A list of available Docker images with their IDs and names.

6. Last-Minute Reference

docker --help shows the full list of available commands and flags.
docker version shows the Docker version.
docker info shows detailed information about the Docker environment.
docker system df shows disk space usage by Docker.
docker system prune removes unused data.
docker rmi -f $(docker images -q) deletes all unused images.
docker rm -f $(docker ps -aq) deletes all stopped containers.
docker stop $(docker ps -aq) stops all running containers.
docker logs -f <container_id> shows container logs.
docker exec -it <container_id> /bin/bash opens a new shell in a running container.
• ⚠️ docker rm -f $(docker ps -aq) deletes all stopped containers, use with caution.




ADVERTISEMENT