Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Introduction to Docker What is Docker Containers vs Virtual Machines Docker Engine Docker Architecture Client Daemon Registry
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-introduction-to-docker-what-is-docker-containers-vs-virtual-machines-docker-engine-docker-architecture-client-daemon-registry

Docker Docker Introduction to Docker What is Docker Containers vs Virtual Machines Docker Engine Docker Architecture Client Daemon Registry

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

⏱️ ~4 min read

1. Core Command / Concept

Understand the difference between containers and virtual machines. docker run -it ubuntu /bin/bash

2. Step-by-Step

  1. Install Docker on your system: sudo apt-get update && sudo apt-get install docker.io
  2. Check if Docker is installed and running: sudo systemctl status docker
  3. ⚠️ Delete all stopped containers: docker container prune
  4. List all running containers: docker ps
  5. Stop a running container: docker stop
  6. Remove a stopped container: docker rm
  7. Clean up all unused images: docker image prune
  8. List all Docker images: docker images

3. Real Commands with Examples


Example 1: Run a simple Ubuntu container

Purpose: Run a basic Ubuntu container.
Command: docker run -it ubuntu /bin/bash
Flags: - -it: Interactive mode, allocates a pseudo-TTY and keeps the container running.
- ubuntu: The image to use.
- /bin/bash: The command to run inside the container.

Example 2: Run a container from a specific image

Purpose: Run a container from a specific image.
Command: docker run -it --name my_container python:3.9 /bin/bash
Flags: - -it: Interactive mode, allocates a pseudo-TTY and keeps the container running.
- --name my_container: Assign a name to the container.
- python:3.9: The image to use.
- /bin/bash: The command to run inside the container.

Example 3: Run a container in detached mode

Purpose: Run a container in detached mode.
Command: docker run -d --name my_container python:3.9 /bin/bash
Flags: - -d: Detached mode, runs the container in the background.
- --name my_container: Assign a name to the container.
- python:3.9: The image to use.
- /bin/bash: The command to run inside the container.

4. Common Errors


Error 1: Unable to pull an image

Error message: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Why it happens: The Docker registry is down or your network connection is slow.
One-line fix: docker pull --quiet

Error 2: Container won't start

Error message: Error response from daemon: Container is already running
Why it happens: The container is already running.
One-line fix: docker stop && docker rm

Error 3: Image won't pull

Error message: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Why it happens: The Docker registry is down or your network connection is slow.
One-line fix: docker pull --quiet

5. Quick Checks


Scenario 1: Check if Docker is installed

Situation: You want to check if Docker is installed on your system.
Command to run: docker --version
Correct response: Docker version 20.10.17, build 100c701d8f

Scenario 2: Check if a container is running

Situation: You want to check if a container is running.
Command to run: docker ps -a
Correct response: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
"/bin/bash" 2 minutes ago Up 2 minutes (healthy) 80/tcp my_container

Scenario 3: Check if an image is available

Situation: You want to check if an image is available.
Command to run: docker images
Correct response: REPOSITORY TAG IMAGE ID CREATED SIZE
2 minutes ago 1.23GB

6. Last-Minute Reference

  • docker run: Run a container from an image.
  • -it: Interactive mode, allocates a pseudo-TTY and keeps the container running.
  • --name: Assign a name to the container.
  • docker ps: List all running containers.
  • docker stop: Stop a running container.
  • docker rm: Remove a stopped container.
  • docker image prune: Clean up all unused images.
  • docker images: List all Docker images.
  • docker pull: Pull an image from the registry.
  • docker push: Push an image to the registry.
  • docker tag: Tag an image with a new name.
  • docker rmi: Remove an image.
  • docker system prune: Clean up all unused containers, images, and networks.
  • docker info: Display information about the Docker environment.
  • docker version: Display the Docker version.
  • docker --version: Display the Docker version.
  • docker inspect: Display detailed information about a container or image.
  • docker logs: Display the logs of a container.
  • docker exec: Execute a command inside a running container.
  • docker attach: Attach to a running container.
  • docker commit: Commit changes to a container as a new image.
  • docker cp: Copy files from a container to the host machine.
  • docker export: Export a container as a tar archive.
  • docker import: Import a tar archive as a Docker image.
  • docker load: Load a Docker image from a tar archive.
  • docker save: Save a Docker image to a tar archive.
  • docker system df: Display disk space usage information.
  • docker stats: Display real-time statistics about containers.
  • docker top: Display the running processes inside a container.
  • docker update: Update a container's configuration.


ADVERTISEMENT