Introduction

Over the past six days, everything I built lived strictly on my local Ubuntu VM. Today, for the final challenge, I published my custom Python + MySQL application image to Docker Hub, versioning it with semantic tags (latest and v1.0), pulling it fresh from the cloud, and running my full Docker Compose stack directly from my cloud-hosted image without needing local source code or a Dockerfile.

1. Exploring Docker Hub

  • What is Docker Hub? Docker Hub is a cloud-based container registry service where developers store, manage, discover, and share Docker images publicly or privately.
  • What is a container registry? A container registry is a centralized storage and distribution system (similar to a package repository) that hosts versioned container images so machines anywhere can download and run them.
  • How is Docker Hub similar to GitHub? Just as GitHub hosts source code repositories where developers git push and git pull code, Docker Hub hosts image repositories where developers docker push and docker pull runnable container images.
  • What is the difference between pushing and pulling an image? Pushing (docker push) uploads a locally built image from your machine up to a cloud registry. Pulling (docker pull) downloads an existing image from a registry onto your local machine.

2. Creating My Docker Hub Account & Logging In

I created my Docker Hub account (meshackmulei) and authenticated directly from my terminal:

docker login 

Image

Image

  • What does docker login do? It authenticates your local Docker CLI with Docker Hub so you have permission to push images to your account and pull private repositories.
  • Where does Docker store authentication information? Docker saves the encoded credentials or token inside ~/.docker/config.json in your home directory (or in your OS credential helper/keyring if configured).
  • Why should you never share your Docker Hub credentials? Anyone with your credentials or access token can push malicious images under your username, overwrite your production tags, or access private repositories. (Never bake passwords, API keys, or tokens into a Dockerfile either!)

3. Understanding Image Naming & Building for Docker Hub

Docker Hub images follow the naming format username/image-name:tag (for example, meshackmulei/my-python-app:latest).

  • What does each part represent?
    • username: Your Docker Hub namespace/account owner (meshackmulei).
    • image-name: The repository name identifying the application (my-python-app).
    • tag: A specific version or variant label (latest or v1.0).
  • What is an image tag? A human-readable pointer attached to a specific image digest so you can track releases and updates.
  • What happens when you don't specify a tag? Docker automatically defaults to the latest tag.
  • Why might developers use version numbers instead of always using latest? latest changes over time whenever new builds are pushed, which can silently break deployments. Explicit version tags (v1.0, v1.1) guarantee predictable, reproducible builds and make rolling back easy.

I navigated to my Day5 folder, verified app.py, requirements.txt, Dockerfile, and docker-compose.yml, and built my tagged image:

cd ~/Day5 ls -la docker build -t meshackmulei/my-python-app:latest . docker images 
  • What does -t do? -t (tag) assigns a repository name and tag to the newly built image.
  • Why must your Docker Hub username be part of the image name? Docker Hub routes pushes based on the namespace prefix; without your exact username at the front, Docker tries to push to Docker's official root library and rejects it with denied: requested access to the resource is denied.

Image

4. Pushing & Verifying My Published Image

Next, I pushed my custom Python image to Docker Hub and verified the repository in my browser:

docker push meshackmulei/my-python-app:latest 

Image

  • What are Docker image layers? Each instruction in a Dockerfile (FROM, COPY, RUN) creates an immutable, read-only filesystem layer stacked on top of the previous one.
  • Why does Docker upload images in layers? Layering enables caching and deduplication—shared base layers (like python:3.11-slim) don't need to be re-uploaded or re-downloaded repeatedly.
  • What happens when you push an updated image, and why is a second push faster? When you edit app.py and rebuild, Docker reuses all unchanged layers (FROM, pip install) from cache and only builds and uploads the tiny modified COPY . . layer, making subsequent pushes much faster.

Checking https://docker.com/meshackmulei/my-python-app confirmed:

  • Available tags: latest
  • Last pushed: Just moments ago
  • Visibility & access: Set to Public, meaning anyone on any machine with Docker installed can pull and run it immediately.

Image

5. Pulling My Image Back from Docker Hub

To prove my image could be retrieved cleanly from the cloud, I deleted my local copy and pulled it back from Docker Hub:

docker rmi meshackmulei/my-python-app:latest docker images docker pull meshackmulei/my-python-app:latest docker images 

Image

6. Versioning My Image (v1.0)

Next, I tagged my image with an explicit release version (v1.0) and pushed it to Docker Hub:

docker tag meshackmulei/my-python-app:latest meshackmulei/my-python-app:v1.0 docker push meshackmulei/my-python-app:v1.0 

Image

  • Does docker tag create a completely new image? No—it creates a new alias/pointer referencing the exact same underlying image ID and layers.
  • What is the difference between latest and v1.0? Right now both point to the exact same image digest, but v1.0 is permanently pinned to this initial release whereas latest will move forward when future updates are pushed.
  • Why is versioning useful when deploying applications? It gives teams clear release tracking, environment parity across staging/production, and instant rollback capability if a new release introduces a bug.

Image

7. Running Docker Compose from My Published Docker Hub Image

Finally, I updated docker-compose.yml to replace build: . with image: meshackmulei/my-python-app:v1.0, deleted my local v1.0 image, and launched the stack so Docker Compose pulled my Python app directly from Docker Hub alongside MySQL:

nano docker-compose.yml docker compose down docker rmi meshackmulei/my-python-app:v1.0 docker compose up -d docker compose ps 
  • Are both containers running? Yes—both day5-app-1 and day5-database-1 started cleanly (Up).
  • Was the Python image pulled from Docker Hub? Yes, because I removed the local v1.0 image first, Compose automatically downloaded meshackmulei/my-python-app:v1.0 from Docker Hub.
  • Can you access http://localhost:5000 and does it still retrieve data from MySQL? Yes. The browser displayed Connected to MySQL successfully!.
  • Does the person deploying this application need your Python source code or Dockerfile? No! All they need is docker-compose.yml (or a single docker run command), because the application code and dependencies are already packaged inside the Docker Hub image.

Image

Image

8. Debugging & Troubleshooting Like an Engineer

When working with Docker Hub and multi-container deployments, here is how to diagnose and resolve the most common issues:

  • Diagnostic commands:
    • docker images - verify local image names, tags, and image IDs.
    • docker compose ps - check whether services are Up, Exited, or restarting.
    • docker compose logs - inspect container output and stack traces.
    • docker compose pull - test pulling images defined in docker-compose.yml before starting containers.
  • Common scenarios & resolutions:
    • Image not found on Docker Hub / Incorrect image name or tag: Double-check the exact username/repository:tag spelling and confirm the tag exists on Docker Hub (or check if the repository is set to Private when you aren't logged in).
    • Authentication failure: Run docker logout followed by docker login using your Docker Hub username and a valid Personal Access Token (PAT) with Read & Write permissions.
    • Application container keeps restarting / Cannot connect to MySQL: Inspect docker compose logs app to confirm DB_HOST matches the MySQL service name (database), DB_PASSWORD matches MYSQL_ROOT_PASSWORD, and give MySQL ~15 seconds to finish initializing on first boot.

9. Summary & Key Takeaways

  • What is Docker Hub? A cloud container registry for storing, versioning, and sharing Docker images globally.
  • What is the difference between docker push and docker pull? docker push uploads a local image to a registry; docker pull downloads an image from a registry to your machine.
  • What are image layers? Immutable filesystem changes stacked per Dockerfile instruction that speed up builds and uploads through layer caching.
  • What is the purpose of image tags? Version labels (latest, v1.0) used to identify, pin, and manage specific image releases.
  • What is the difference between build: and image: in Compose? build: compiles an image locally from a Dockerfile, whereas image: pulls a pre-built image from a registry like Docker Hub.
  • Why is Docker Hub useful when deploying applications? It decouples building from running, allowing any server or teammate to pull and run the same tested application artifact in seconds without needing source code or build tools.