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 pushandgit pullcode, Docker Hub hosts image repositories where developersdocker pushanddocker pullrunnable 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
-
What does
docker logindo? 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.jsonin 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
Dockerfileeither!)
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 (latestorv1.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
latesttag. -
Why might developers use version numbers instead of always using
latest?latestchanges 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
-tdo?-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.
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
-
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.pyand rebuild, Docker reuses all unchanged layers (FROM,pip install) from cache and only builds and uploads the tiny modifiedCOPY . .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.
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
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
-
Does
docker tagcreate 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
latestandv1.0? Right now both point to the exact same image digest, butv1.0is permanently pinned to this initial release whereaslatestwill 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.
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-1andday5-database-1started cleanly (Up). -
Was the Python image pulled from Docker Hub? Yes, because I removed the local
v1.0image first, Compose automatically downloadedmeshackmulei/my-python-app:v1.0from Docker Hub. -
Can you access
http://localhost:5000and does it still retrieve data from MySQL? Yes. The browser displayedConnected to MySQL successfully!. -
Does the person deploying this application need your Python source code or
Dockerfile? No! All they need isdocker-compose.yml(or a singledocker runcommand), because the application code and dependencies are already packaged inside the Docker Hub 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 areUp,Exited, or restarting. -
docker compose logs- inspect container output and stack traces. -
docker compose pull- test pulling images defined indocker-compose.ymlbefore starting containers.
-
-
Common scenarios & resolutions:
-
Image not found on Docker Hub / Incorrect image name or tag: Double-check the exact
username/repository:tagspelling 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 logoutfollowed bydocker loginusing 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 appto confirmDB_HOSTmatches the MySQL service name (database),DB_PASSWORDmatchesMYSQL_ROOT_PASSWORD, and give MySQL ~15 seconds to finish initializing on first boot.
-
Image not found on Docker Hub / Incorrect image name or tag: Double-check the exact
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 pushanddocker pull?docker pushuploads a local image to a registry;docker pulldownloads an image from a registry to your machine. -
What are image layers? Immutable filesystem changes stacked per
Dockerfileinstruction 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:andimage:in Compose?build:compiles an image locally from aDockerfile, whereasimage: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.










Top comments (0)