SkillSprout
Chapter 1 · Lesson 5
Beginner
1 min read

Pull Images and Inspect Docker Resources

Overview

Running docker run nginx can hide an important step: Docker first looks for a local image, and if it is missing, downloads the image from a registry. Pulling separately makes that behavior visible and lets you verify which tag or version exists locally.

Detailed Notes

Pull an exact image

bash
docker pull nginx:1.27-alpine

The text before : is the repository name. The text after : is the tag. Docker Hub is used by default when no registry hostname is included.

Expected behavior:

  1. Docker asks the registry for the requested tag.
  2. The registry returns a manifest listing image layers.
  3. Docker downloads only missing layers.
  4. The image becomes available in the local image cache.

Inspect local resources

bash
docker images
docker image ls
docker image inspect nginx:1.27-alpine
docker history nginx:1.27-alpine
  • docker images and docker image ls list downloaded images.
  • inspect prints configuration in JSON, including architecture, environment, entrypoint and exposed ports.
  • history shows how the image was assembled and the size contributed by each step.

To remove an image:

bash
docker rmi nginx:1.27-alpine

Docker refuses removal if a container still depends on the image. Remove the container first, or use docker rm -f CONTAINER_NAME only when the running container is no longer needed.

Practice

Pull nginx:1.27-alpine, list it, inspect it and run:

bash
docker run --rm nginx:1.27-alpine nginx -v

This is an example of overriding the image's default command. The container starts, prints the Nginx version and exits.

Common Interview Questions

Finished this lesson?

0 of 27 lessons done · 0% of the course