Skip to content

BMSihlas/dataops-docker-flask-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataOps Exercise - PostgreSQL and Flask Docker Compose

Overview

This repository consists of a Python project that uses Docker Compose to run a PostgreSQL database and a Flask API. The API is used to interact with the database and perform CRUD operations.

1 - Requirements

  • A version of Docker installed

2 - Setup Instructions

This project uses environment variables to configure the database connection. To set up the environment variables, create a .env file in the root directory of the project with the following content:

## .env
## web container
DBNAME=your_db_name
USER=your_db_user
PASSWORD=your_db_password
HOST=host.docker.internal   # as the database is running in a container, the host is the host machine
PORT=5432   # default port for PostgreSQL

## db container
POSTGRES_USER=your_db_user
POSTGRES_PASSWORD=your_db_password
POSTGRES_DB=your_db_name

In db/init.sql, you can find the SQL script that creates a table in the database. You can modify this script to create your own tables. This script is executed when the database container is started.

3 - Start/stop the containers

To start the containers, run the following command in the root directory of the project:

docker-compose --env-file .env up --build -d

To stop the containers, run the following command:

docker-compose stop

In case you want to stop and remove the containers, run the following command:

docker-compose down -v

4 - Access the API

The API is available at http://localhost:5000. You can use a tool like Postman to interact with the API.

Endpoints

  • GET /: "Hello, Docker Compose with PostgreSQL!"
  • GET /data: List of results from a table in the database

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published