Using Multiple Docker Containers to Setup Nginx, Flask and Postgres

Image for post
Image for post
Docker with Nginx, Flask and Postgres

Terminology

Prerequisites

Nginx

Dockerfile

Image for post
Image for post
Dockerfile

example.conf

Image for post
Image for post
example.conf

Flask

Dockerfile

Image for post
Image for post
Dockerfile

uwsgi.ini

Image for post
Image for post
uwsgi.ini

Postgres

database.conf

Image for post
Image for post
database.conf

docker-compose.yml

Image for post
Image for post
docker-compose.yml

web_server

app

database

Docker Compose Build/Run

docker-compose up --build -d

Docker Build/Run

# Build our images first
docker build -f docker/nginx/Dockerfile -t nginx .
docker build -f docker/flask/Dockerfile -t flask .

# Run our containers
docker run -d --name nginx -p 80:80 nginx
docker run -d --name flask -p 8080 --env-file docker/database.conf flask
docker volume create --name db_volume
docker run -d --name postgres -p 5432:5432 \
--env-file docker/database.conf \
-v db_volume:/var/lib/postgresql postgres:latest

Written by

Software Engineer | Pythonista | Typescripter | Docker Advocate | https://haseebmajid.dev

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store