Module 11 Lesson 2: Pushing and Pulling Images
·DevOps

Module 11 Lesson 2: Pushing and Pulling Images

Master the image transition. Learn how to log in to various services, tag your images for specific registries, and 'Push' your code to the cloud.

Module 11 Lesson 2: Pushing and Pulling Images

To share an image, you must perform three steps: Login, Tag, and Push.

1. Authentication (docker login)

Before you can push to a private registry (or even pull, in some cases), you must authenticate.

  • Docker Hub: docker login
  • GitHub: docker login ghcr.io -u <YOUR_USERNAME> (You'll use a Personal Access Token as the password).
  • AWS ECR: AWS uses a special command line tool to generate a temporary password for you: aws ecr get-login-password | docker login --username AWS --password-stdin <YOUR_ID>.dkr.ecr.us-east-1.amazonaws.com

2. Tagging for the Registry

Docker determines where to push an image based on the First Part of the image name.

  1. Build your local image: docker build -t my-app:test .
  2. Tag it for the registry: docker tag my-app:test ghcr.io/my-username/production-app:v1.0.0

3. The Push Command

Now, you send the layers to the cloud: docker push ghcr.io/my-username/production-app:v1.0.0

Only the changes are sent: If you have already pushed v1.0.0 and you are now pushing v1.0.1, Docker will see that the OS and library layers are the same. It only uploads the tiny layer containing your code change.


4. Pulling on the Server

Once pushed, any other computer can download it: docker pull ghcr.io/my-username/production-app:v1.0.0


5. Security Warning: The config.json

When you docker login, your credentials (or tokens) are saved in a plain-text file on your computer: ~/.docker/config.json.

  • The Danger: If someone gains access to your laptop, they can steal this file and push malicious images to your registry!
  • The Fix: Use a "Credential Helper" (like the ones built-in to Docker Desktop) which stores the secrets in your OS's Keychain or Wallet instead.

Exercise: The Registry Relay

  1. Create a free account on Docker Hub.
  2. Build a tiny "Hello World" image.
  3. docker login using your terminal.
  4. Tag your image with your Docker Hub username: docker tag my-app:v1 <your-username>/my-hello:v1.
  5. docker push it.
  6. Go to the Docker Hub website and find your image.
  7. Ask a teammate to pull your image. Did it work?

Summary

Pushing and pulling is the "Heartbeat" of modern deployment. By mastering the login/tag/push workflow, you enable your CI/CD pipelines to automatically deliver new features to your users every time you commit code.

Next Lesson: Robot automation: CI/CD integration with Docker.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn