Welcome to the final level of the Docker course!
In this level, we’ll combine all the knowledge and skills you've gained so far.
In the lectures, you might come across programming languages or technologies you're not familiar with. You’ll have tasks like opening ports or adding method names – all based on pre-written code where 99% of the work is already done.
Don’t worry if some things seem unfamiliar – this is intentionally done to help you build the skill of: "I don't know this, but I can figure it out quickly".
1.1 Setting the Task
Let’s create a small multi-container app and go through each step of the development process: from defining the task to showcasing the finished product.
Goal: build a multi-container task management app that lets users create, edit, delete tasks, and assign them to other users. The app will have three main components: a frontend using ReactJS, a backend using Python (Flask), and a PostgreSQL database.
Main tasks:
- Define the functional requirements for each component of the app.
- Choose the technologies and tools to use.
- Set up the development environment.
1.2 Defining Functional Requirements
Functional requirements for the task management app:
- User registration and login:
- The user can register in the system.
- The user can log in to the system.
- Task management:
- The user can create tasks.
- The user can edit tasks.
- The user can delete tasks.
- The user can view the list of tasks.
- The user can assign tasks to other users.
- Viewing and filtering tasks:
- The user can filter tasks by status (completed/uncompleted).
- The user can view tasks assigned to other users.
1.3 Defining the Technologies and Tools Used
To build this app, the following technologies and tools will be used:
- Frontend:
- ReactJS: a library for building user interfaces.
- Axios: a library for making HTTP requests.
- Backend:
- Python: a programming language for creating the server side.
- Flask: a web framework for building REST APIs.
- SQLAlchemy: an ORM for interacting with the database.
- Database:
- PostgreSQL: a relational database for storing user and task information.
- Containerization and Orchestration:
- Docker: a platform for containerizing applications.
- Docker Compose: a tool for managing multi-container apps.
1.4 Setting up the Development Environment
To successfully complete the project, you need to set up the development environment and ensure all the necessary tools are installed.
Steps to set up the environment:
- Installing Docker:
- If you haven't done this yet, go back to Lecture 4 of the first level or follow the instructions on the official Docker website.
- Installing Docker Compose:
- If Docker Compose is not installed yet, refer to Lecture 2 of level 4 or follow the instructions on the official Docker Compose website.
- Creating the project structure:
- Create a directory for the project and main subdirectories for each service:
mkdir task_management_app
cd task_management_app
mkdir frontend backend database
- Initializing the project:
- Inside the frontend directory, initialize a new ReactJS project:
cd frontend
npx create-react-app .
cd ..
• Inside the backend directory, create a structure for a Python/Flask application:
cd backend
mkdir app
touch app/__init__.py
touch app/models.py
touch app/routes.py
touch run.py
touch requirements.txt
cd ..
• Inside the database directory, create a Dockerfile for PostgreSQL (if needed):
cd database
touch Dockerfile
cd ..
1.5 Example of File Contents:
File backend/app/__init__.py:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://taskuser:taskpassword@database:5432/taskdb'
db = SQLAlchemy(app)
from app import routes
File backend/app/models.py:
from app import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
tasks = db.relationship('Task', backref='owner', lazy=True)
class Task(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(120), nullable=False)
description = db.Column(db.Text, nullable=True)
owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
File backend/app/routes.py:
from app import app
@app.route('/')
def index():
return "Hello, Task Management App!"
File backend/run.py:
from app import app
if __name__ == '__main__':
app.run(host='0.0.0.0')
File backend/requirements.txt:
Flask
Flask-SQLAlchemy
psycopg2-binary
GO TO FULL VERSION