Hey Devs! 👋
In this post, let’s learn how to create your own Docker image and upload it to DockerHub like a pro! 🐳
I’ll keep it super simple — plus, I’ll tell you where you can add screenshots to make the post even cooler!
⸻
🛠️ Step 1: Create Your Project
👉 Start with a simple app/project.
Example structure:
/my-app
├── app.py
└── requirements.txt
⸻
🐳 Step 2: Create a Dockerfile
Inside your project folder, create a file named Dockerfile (no extension).
Example Dockerfile:
# Use an official Python image
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Copy app files
COPY . .
# Install dependencies
RUN pip install -r requirements.txt
# Run the app
CMD ["python", "app.py"]
⸻
🏗️ Step 3: Build the Docker Image
Now, let’s build your image! Run this in your terminal:
docker build -t your_dockerhub_username/your-image-name:tag .
Example:
docker build -t SysSyncer/hello-world-py:latest .
⸻
🕵️♂️ Step 4: Verify Your Image
Check if your image is created:
docker images
⸻
🔐 Step 5: Login to DockerHub
If you haven’t already, login to your DockerHub account:
docker login
It will ask for your username and password.
⸻
📤 Step 6: Push the Image to DockerHub
Now push your image to the cloud!
docker push your_dockerhub_username/your-image-name:tag
Example:
docker push SysSyncer/hello-world-py:latest
⸻
🎉 Step 7: Done! View Your Image on DockerHub
Go to https://hub.docker.com/ and you’ll see your freshly pushed image under Repositories!
⸻
📋 Full Command Summary
# Build
docker build -t your_dockerhub_username/your-image-name:tag .
# Check Image
docker images
# Login
docker login
# Push
docker push your_dockerhub_username/your-image-name:tag
⸻
⚡ Bonus Tip: Tagging Latest
Want your users to always get the latest version?
Add another tag:
docker tag your_dockerhub_username/your-image-name:v1 your_dockerhub_username/your-image-name:latest
docker push your_dockerhub_username/your-image-name:latest
⸻
🎯 Wrapping Up
And that’s it, champ! 🏆
You just built and published your first Docker image to DockerHub!
Imagine millions of servers now being able to pull and run your image with just:
docker pull your_dockerhub_username/your-image-name:tag
Pretty cool, right? 😎🐳