
π How to Create and Publish Your Own Docker Package (Hello World Django)
Have you ever wanted to package your Django app into a Docker image and share it with the world — just like ghcr.io
container packages? In this tutorial, we’ll walk through how to:
-
Dockerize a Django app (Hello World)
-
Build it into an image
-
Push it to GitHub Container Registry (GHCR)
-
Make it publicly available
π Step 1: Project Setup
Create a simple Django app (or use your existing one). You should have a project structure like this:
docker-django-deploy/
βββ Dockerfile
βββ requirements.txt
βββ manage.py
βββ hello/
βββ helloworld/
βββ ...
π³ Step 2: Write Your Dockerfile
Here’s a minimal and clean Dockerfile
for your Django app:
FROM python:3.10-slim
WORKDIR /app
COPY . .
RUN pip install --upgrade pip && \
pip install -r requirements.txt
EXPOSE 8080
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
π Step 3: Generate a Personal Access Token (PAT) on GitHub
-
Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
-
Click Generate new token
-
Select scopes:
-
write:packages
β -
read:packages
β -
(Optional)
delete:packages
-
-
Click Generate token and copy it immediately (you won’t see it again).
π Step 4: Log In to GitHub Container Registry
echo YOUR_PAT | docker login ghcr.io -u YOUR_GITHUB_USERNAME --password-stdin
Example:
echo ghp_abcd1234xyz | docker login ghcr.io -u imvickykumar999 --password-stdin
ποΈ Step 5: Build Your Docker Image
From your project directory:
docker build -t ghcr.io/imvickykumar999/docker-django-deploy:latest .
This tells Docker to:
-
Use the current directory (
.
) -
Tag the image for GHCR
π€ Step 6: Push Your Image to GHCR
docker push ghcr.io/imvickykumar999/docker-django-deploy:latest
You’ll see the layers get uploaded. Once done, visit:
π https://github.com/imvickykumar999/docker-django-deploy/pkgs/container/docker-django-deploy
π Optional: Make Your Package Public
To let others pull your image without login:
-
Go to the package page
-
Click "Package settings"
-
Change Visibility to Public
π₯ Step 7: Pull and Run the Image Anywhere
On another machine or VM:
docker pull ghcr.io/imvickykumar999/docker-django-deploy:latest
docker run -p 8000:8000 ghcr.io/imvickykumar999/docker-django-deploy:latest
π You Did It!
You now have:
β
A Dockerized Django app
β
Published on GitHub Container Registry
β
Reusable and shareable with the world
π Bonus: Automate with GitHub Actions
You can even set up a .github/workflows/publish.yml
to automatically build and push your Docker image on every git push
. (Let me know if you want this too.)
π¬ Have questions? Drop a comment or open an issue in your GitHub repo.
1 Comments
Vicky Kumar
Created my Own Docker Image, thanks to this blog. URL: ghcr.io/imvickykumar999/flask-cms-gunicorn