Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Vicky Kumar edited this page Jun 16, 2025 · 1 revision

πŸš€ How to Create and Publish Your Own Docker Package (Hello World Django)

image

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:

  1. Go to the package page

  2. Click "Package settings"

  3. 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.