Skip to content

maronworks/django-docker-postgresql-setup

Repository files navigation

📝 Notes API with Docker and PostgreSQL

This project is a simple Django REST API for managing notes, running inside Docker containers with **PostgreSQL ** as the database.


🚀 Setup

  1. Make sure you have Docker and Docker Compose installed.

  2. Clone the repository:

git clone https://github.com/ralphmarondev/django-docker-setup.git
cd django-docker-setup
  1. Build and start the containers:
docker compose up --build
  1. Apply database migrations:
docker compose exec web python manage.py makemigrations
docker compose exec web python manage.py migrate
  1. Visit the API at:
http://localhost:8000/api/

📦 Using the API

The Notes API allows you to create, list, and view notes. You can test it using tools like Postman, * Insomnia*, or curl.


🔍 GET all notes

Endpoint:

GET http://localhost:8000/api/notes/

Sample response:

[
  {
    "id": 1,
    "title": "Hello docker",
    "content": "Is this working?",
    "create_date": "2025-06-12T04:49:38.100576Z",
    "is_deleted": false
  }
]

➕ Create a note

Endpoint:

POST http://localhost:8000/api/note/create/

Request body:

{
  "title": "Hello docker",
  "content": "Is this working?"
}

Response:

{
  "message": "Note created successfully",
  "note": {
    "id": 1,
    "title": "Hello docker",
    "content": "Is this working?",
    "create_date": "2025-06-12T04:59:19.929110Z",
    "is_deleted": false
  }
}

🗄️ Viewing the PostgreSQL database

You can view your notes and other tables directly from the running PostgreSQL container.

  1. Enter the PostgreSQL container:
docker compose exec db psql -U postgres -d hello
  1. List all tables:
\dt
  1. Show notes:
SELECT * FROM notes_note;
  1. Show Django users (if applicable):
SELECT * FROM auth_user;
  1. Exit the database shell:
\q

🛑 Stopping the app

To stop the containers:

docker compose down

🧪 Environment Configuration

Edit .env for local credentials:

# PostgreSQL Config
POSTGRES_DB=hello
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DB_HOST=db
DB_PORT=5432

# Django Config
DEBUG=True
SECRET_KEY=your-secret-key

A sample is available as .env_sample.


✅ Summary

  • Django + DRF-based Notes API
  • Dockerized with PostgreSQL
  • Easy to run locally and ready for production setups
  • Tested with Postman

Feel free to fork and expand this for your own apps 🚀

About

Simple Django Rest using Postgresql DB with Docker :)

Resources

Stars

Watchers

Forks