Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Images and Containers Docker Images Layers Tags Image Registry Docker Hub ECR ACR
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-images-and-containers-docker-images-layers-tags-image-registry-docker-hub-ecr-acr

Docker Docker Images and Containers Docker Images Layers Tags Image Registry Docker Hub ECR ACR

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

⏱️ ~2 min read

1. Core Command / Concept

Create a Docker image with multiple layers and tags. docker build.

2. Step-by-Step

  1. Create a new directory for your project and navigate to it: mkdir docker-image && cd docker-image
  2. Create a new file named Dockerfile with the following content: FROM ubuntu:latest
  3. Build the Docker image with the name my-image and tag v1: docker build -t my-image:v1 .
  4. List all Docker images: docker images
  5. Check the image layers: docker inspect -f '{{ .GraphDriver.Data.Layers }}' my-image:v1
  6. ⚠️ Delete the image: docker rmi my-image:v1

3. Real Commands with Examples


Example 1: Create a Docker image with a custom tag

Purpose: Create a Docker image with a custom tag.
Command: docker build -t my-image:v2 . Flags: -t specifies the image name and tag.

Example 2: Create a Docker image with a parent image

Purpose: Create a Docker image with a parent image.
Command: docker build -t my-image -f Dockerfile.parent . Flags: -f specifies the Dockerfile to use.

Example 3: Push a Docker image to a registry

Purpose: Push a Docker image to a registry.
Command: docker tag my-image:v1 my-username/my-image:v1 && docker push my-username/my-image:v1 Flags: docker tag assigns a new name to the image, and docker push uploads the image to a registry.

4. Common Errors


Error 1: Image not found

Error message: Error: No such image: my-image:v1 Why it happens: The image does not exist in the local Docker cache.
One-line fix: docker build -t my-image:v1 .

Error 2: Build failed

Error message: Error: failed to solve: ... Why it happens: The Dockerfile contains an error or the image cannot be built.
One-line fix: Check the Dockerfile for errors and correct them.

Error 3: Push failed

Error message: Error: failed to push some refs: ... Why it happens: The image cannot be pushed to the registry due to authentication or permission issues.
One-line fix: Check the registry credentials and permissions.

5. Quick Checks


Scenario 1: Check if an image exists

Situation: You want to check if an image exists in the local Docker cache.
Command: docker images Correct response: The image name and tag should be listed.

Scenario 2: Check the image layers

Situation: You want to check the image layers.
Command: docker inspect -f '{{ .GraphDriver.Data.Layers }}' my-image:v1 Correct response: The image layers should be listed.

Scenario 3: Check the image size

Situation: You want to check the image size.
Command: docker images -f "dangling=true" --format "{{.Size}}" Correct response: The image size should be listed in bytes.

6. Last-Minute Reference

docker build flags: -t, -f, -q, -no-cachedocker images flags: -a, -f, -qdocker inspect flags: -f, -formatdocker rmi flags: -f, -no-prune • ⚠️ docker rmi deletes all stopped containers • ⚠️ docker system prune deletes all unused data • docker tag flags: -f, -mdocker push flags: -t, -u




ADVERTISEMENT