Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Introduction to Docker Why Docker Reproducibility Portability Isolation Efficiency
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-introduction-to-docker-why-docker-reproducibility-portability-isolation-efficiency

Docker Docker Introduction to Docker Why Docker Reproducibility Portability Isolation Efficiency

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

Docker provides reproducibility, portability, isolation, and efficiency by packaging applications and their dependencies into containers. docker run

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: docker --version and sudo systemctl status docker
  3. Create a new Dockerfile in a directory: touch Dockerfile
  4. Build an image from the Dockerfile: docker build -t myimage .
  5. Run a container from the image: docker run -it myimage
  6. ⚠️ Delete all stopped containers: docker container prune
  7. List all running containers: docker ps
  8. Stop a running container: docker stop <container_id>

3. Real Commands with Examples


Example 1: Run a simple web server

Purpose: Run a web server using the official Python image.
Command: docker run -p 8080:80 python:3.9-slim Flags: -p maps port 8080 on the host to port 80 in the container, python:3.9-slim is the image name.

Example 2: Run a database server

Purpose: Run a PostgreSQL database server.
Command: docker run -d -p 5432:5432 --name mydb postgres:13 Flags: -d runs the container in detached mode, -p maps port 5432 on the host to port 5432 in the container, --name sets the container name, postgres:13 is the image name.

Example 3: Run a command in a container

Purpose: Run the ls command in a container.
Command: docker run -it --rm alpine ls -l Flags: -it runs the container in interactive mode, --rm removes the container after it exits, alpine is the image name.

4. Common Errors


Error 1: Image not found

Error message: docker: Error response from daemon: No such image: myimage.
Why it happens: The image does not exist locally or on the Docker registry.
Fix: docker pull myimage.

Error 2: Container not found

Error message: docker: Error response from daemon: No such container: mycontainer.
Why it happens: The container does not exist.
Fix: docker ps -a to list all containers.

Error 3: Port already in use

Error message: docker: Error response from daemon: Port is already allocated.
Why it happens: The port is already in use by another container or process.
Fix: docker ps -a to list all containers and find the one using the port, then docker stop and docker rm to stop and remove the container.

5. Quick Checks


Scenario 1: Check if Docker is installed

Situation: You want to check if Docker is installed on your system.
Command: docker --version Correct response: The Docker version number.

Scenario 2: Check if a container is running

Situation: You want to check if a container is running.
Command: docker ps Correct response: The container ID and name.

Scenario 3: Check if an image exists

Situation: You want to check if an image exists locally.
Command: docker images Correct response: The image ID and name.

6. Last‑Minute Reference

  • docker run flags: -d, -p, -it, --rm, --name
  • docker build flags: -t, . (current directory)
  • docker ps flags: -a (all containers), -q (quiet mode)
  • docker stop flags: <container_id>
  • docker rm flags: <container_id>
  • docker pull flags: <image_name>
  • docker push flags: <image_name>
  • docker tag flags: <image_id>, <image_name>
  • docker rmi flags: <image_id>
  • ⚠️ docker container prune deletes all stopped containers.
  • ⚠️ docker system prune deletes all unused data.
  • ⚠️ docker image prune deletes all unused images.


ADVERTISEMENT