Skip to content

Images and Registries

First PublishedByAtif Alam

Docker images are read-only templates. You build them from a Dockerfile, tag them for a registry, and push or pull them to share or deploy.

Terminal window
# Build from current directory (looks for Dockerfile)
docker build -t myapp:1.0 .
# Build from a different path or Dockerfile
docker build -f Dockerfile.prod -t myapp:prod ./app

The -t flag tags the image (name and optional tag). If you omit the tag, Docker uses latest.

Each Dockerfile instruction that changes the filesystem creates a layer. Layers are cached; if a step hasn’t changed, Docker reuses the cached layer. Put rarely changing steps (e.g. COPY package*.json and RUN npm ci) before frequently changing ones (e.g. COPY . .) to improve cache hits.

Tags identify a specific image. Format: [registry/][owner/]name[:tag].

Terminal window
# Local tag
docker tag myapp:1.0 myapp:latest
# Tag for Docker Hub (push to your username)
docker tag myapp:1.0 myuser/myapp:1.0
# Tag for Amazon ECR
docker tag myapp:1.0 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:1.0
RegistryUse case
Docker HubPublic and private images; docker.io by default.
Amazon ECRAWS; integrates with IAM and ECS/EKS.
Google Container Registry (GCR)GCP; integrates with GKE.
GitHub Container Registry (ghcr.io)Store images next to your repos.
Terminal window
# Log in to Docker Hub
docker login
# Push to Docker Hub
docker push myuser/myapp:1.0
# Pull an image (defaults to Docker Hub if no registry in the name)
docker pull nginx:alpine
docker pull 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:1.0

For ECR, authenticate with the AWS CLI first: aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com.

Terminal window
docker image ls # List local images
docker image rm <id> # Remove an image
docker image prune # Remove dangling images
docker image inspect <id> # Inspect image metadata and layers
  • Build with docker build -t name:tag .; use layer order and .dockerignore for fast, repeatable builds.
  • Tag images for your registry (e.g. myuser/myapp:1.0 or ECR URL).
  • Push after docker login; pull to fetch images. Use ECR/GCR/ghcr.io for private or cloud-native workflows.