Skip
Arish's avatar

5. Understanding Docker Images


What is a Docker Image?

An image is a read-only template with instructions for creating a container.

Image Layers

Images are built in layers:

┌─────────────────────────────┐ │ Application Code │ <- Your code ├─────────────────────────────┤ │ Dependencies │ <- npm, gems, etc. ├─────────────────────────────┤ │ Runtime │ <- Node, Ruby, etc. ├─────────────────────────────┤ │ Base OS │ <- Ubuntu, Alpine └─────────────────────────────┘

Viewing Layers

bash
1docker history nginx

Image Tags

Images use tags for versioning:

bash
1nginx:latest
2nginx:1.24
3nginx:1.24-alpine
4ruby:3.2
5ruby:3.2-slim
6ruby:3.2-alpine

Best Practices

  • Use specific tags, not latest
  • Use slim/alpine for smaller images
  • Official images are verified