Sub topic 3
Tagging, Pushing, and Pulling Docker Images
Assume you know basic command-line use, can run containers, and have Docker installed. An image reference usually has this form:
registry/repository:tag
For example, registry.example.com/team/web:1.0 identifies a registry, repository, and tag. A tag is a movable name. It can point to different image content later.
Tagging, Pushing, and Pulling
Build and tag an image locally:
docker build -t myapp:1.0 .
docker tag myapp:1.0 registry.example.com/team/myapp:1.0
docker push registry.example.com/team/myapp:1.0
docker pull registry.example.com/team/myapp:1.0docker tag adds another name. It does not copy the image. docker push uploads the layers and metadata that the registry does not already have. docker pull downloads the content needed locally.
Logging In to a Registry
Authenticate before pushing to a private registry:
docker login registry.example.comDocker stores credentials using its configured credential helper when available. Use a short-lived token or registry-specific access token instead of a personal password. Give the token only the permissions required for the repository.
Pinning Images by Digest
A digest is a cryptographic identifier for exact image content. Unlike a tag, it does not move when a registry publishes a newer image.
docker pull alpine@sha256:<digest>Use digest references for production deployments when reproducibility matters. Tags remain convenient for development and release labels.
Running a Local Registry for Testing
A local registry is useful for testing push and pull workflows without an external service:
docker run -d -p 5000:5000 --name registry registry:2
docker tag myapp:1.0 localhost:5000/myapp:1.0
docker push localhost:5000/myapp:1.0
docker pull localhost:5000/myapp:1.0A production registry needs TLS and authentication. This simple setup is intended for local experiments.
Multi-Platform Images
A multi-platform build publishes an image index. The index points to separate images for architectures such as amd64 and arm64. Docker selects the matching image when pulling.
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t registry.example.com/team/myapp:1.0 \
--push .
docker buildx imagetools inspect registry.example.com/team/myapp:1.0Image Security Basics
Use trusted, maintained base images. Scan images for known vulnerabilities, minimize installed packages, avoid embedded secrets, and run as a non-root user where practical. Pin important base images by digest and rebuild them when security fixes are released.
Retention and Cleanup
Registries accumulate old tags and unreferenced layers. Define retention rules for temporary builds, keep release artifacts longer, and delete unused manifests according to your rollback policy. Confirm that a digest is no longer needed before removing it.
Exercise
Why is a digest safer than a tag for a production deployment?
Show answer
A digest identifies exact content, while a tag can be moved to different content.