Skip to content

Latest commit

 

History

History
174 lines (129 loc) · 3.45 KB

File metadata and controls

174 lines (129 loc) · 3.45 KB

Docker Task API

A small Dockerized REST API for managing tasks, built with Node.js, Express, PostgreSQL, and Docker Compose.

The project demonstrates how to containerize an application, connect multiple services through Docker networking, persist database data, validate containers automatically, and publish reusable Docker images.

Kubernetes deployment is handled by the companion project: kubernetes-task-manager.

Tech Stack

  • Node.js 22
  • Express 5
  • PostgreSQL 17
  • Docker
  • Docker Compose
  • GitHub Actions
  • GitHub Container Registry

Architecture

Client
  |
  | HTTP :3000
  v
Node.js / Express
Docker Container
  |
  | database:5432
  v
PostgreSQL
Docker Container
  |
  v
postgres_data
Docker Volume

Docker Compose creates an internal network where the API communicates with PostgreSQL using the service hostname database.

Features

  • REST CRUD API
  • PostgreSQL persistence
  • Dockerized API
  • Docker Compose multi-container environment
  • Database health checks
  • Persistent Docker volumes
  • Automatic database initialization
  • Parameterized SQL queries
  • PowerShell helper scripts
  • Docker CI validation
  • Automated container image publishing

Quick Start

Clone the repository:

git clone https://github.com/gabrielacebal/docker-task-api.git
cd docker-task-api

Start the application:

docker compose up --build

The API will be available at:

http://localhost:3000

Test it:

curl http://localhost:3000/tasks

For detailed setup instructions and troubleshooting, see SETUP.md.

API

Method Endpoint Description
GET /tasks Get all tasks
GET /tasks/:id Get a task
POST /tasks Create a task
PUT /tasks/:id Update a task
DELETE /tasks/:id Delete a task

Example:

curl -X POST http://localhost:3000/tasks \
  -H "Content-Type: application/json" \
  -d '{"title":"Learn Docker"}'

Docker Commands

docker compose up --build
docker compose ps
docker compose logs -f
docker compose down

Reset the database:

docker compose down -v

CI/CD

GitHub Actions validates the Docker stack on pull requests by:

  1. validating the Docker Compose configuration;
  2. building the containers;
  3. starting the API and PostgreSQL;
  4. running CRUD smoke tests;
  5. cleaning up the environment.

On pushes to main, the workflow also publishes the API image to GitHub Container Registry:

ghcr.io/gabrielacebal/docker-task-api

This image can then be consumed by the Kubernetes deployment project.

Related Project

Kubernetes Task Manager

kubernetes-task-manager

The Kubernetes repository is responsible for deploying and orchestrating the container image generated by this project.

docker-task-api
      |
      | build
      v
Docker Image
      |
      | deploy
      v
kubernetes-task-manager

This separation keeps application containerization and Kubernetes orchestration independent.

Documentation

Purpose

This repository is a small practical project for learning and demonstrating Docker concepts including:

  • images
  • containers
  • networking
  • volumes
  • Docker Compose
  • service discovery
  • health checks
  • container registries
  • CI/CD