By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Create a Docker image with multiple layers and tags. docker build.
mkdir docker-image && cd docker-image
Dockerfile
FROM ubuntu:latest
my-image
v1
docker build -t my-image:v1 .
docker images
docker inspect -f '{{ .GraphDriver.Data.Layers }}' my-image:v1
docker rmi my-image:v1
Purpose: Create a Docker image with a custom tag.Command: docker build -t my-image:v2 . Flags: -t specifies the image name and tag.
docker build -t my-image:v2 .
-t
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.
docker build -t my-image -f Dockerfile.parent .
-f
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.
docker tag my-image:v1 my-username/my-image:v1 && docker push my-username/my-image:v1
docker tag
docker push
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: No such image: my-image:v1
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: failed to solve: ...
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.
Error: failed to push some refs: ...
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.
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.
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.
docker images -f "dangling=true" --format "{{.Size}}"
• docker build flags: -t, -f, -q, -no-cache • docker images flags: -a, -f, -q • docker inspect flags: -f, -format • docker rmi flags: -f, -no-prune • ⚠️ docker rmi deletes all stopped containers • ⚠️ docker system prune deletes all unused data • docker tag flags: -f, -m • docker push flags: -t, -u
-q
-no-cache
-a
-format
-no-prune
-m
-u
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.