-
Notifications
You must be signed in to change notification settings - Fork 2
Home
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
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/
βββ ...
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"]
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).
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
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
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
To let others pull your image without login:
-
Go to the package page
-
Click "Package settings"
-
Change Visibility to Public
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 now have:
β
A Dockerized Django app
β
Published on GitHub Container Registry
β
Reusable and shareable with the world
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.
