CodeGym /Courses /Docker SELF /Docker Workflow Demo

Docker Workflow Demo

Docker SELF
Level 23 , Lesson 0
Available

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:

  1. Define the functional requirements for each component of the app.
  2. Choose the technologies and tools to use.
  3. Set up the development environment.

1.2 Defining Functional Requirements

Functional requirements for the task management app:

  1. User registration and login:
    • The user can register in the system.
    • The user can log in to the system.
  2. 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.
  3. 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:

  1. Frontend:
    • ReactJS: a library for building user interfaces.
    • Axios: a library for making HTTP requests.
  2. 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.
  3. Database:
    • PostgreSQL: a relational database for storing user and task information.
  4. 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:

  1. 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.
  2. 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.
  3. Creating the project structure:
    • Create a directory for the project and main subdirectories for each service:
Terminal

mkdir task_management_app
cd task_management_app
mkdir frontend backend database
        
  1. Initializing the project:
    • Inside the frontend directory, initialize a new ReactJS project:
Terminal

cd frontend
npx create-react-app .
cd ..
        

• Inside the backend directory, create a structure for a Python/Flask application:

Terminal

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):

Terminal

cd database
touch Dockerfile
cd ..
        

1.5 Example of File Contents:

File backend/app/__init__.py:

Python

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:

Python

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:

Python

from app import app

@app.route('/')
def index():
    return "Hello, Task Management App!"
    

File backend/run.py:

Python

from app import app

if __name__ == '__main__':
    app.run(host='0.0.0.0')
    

File backend/requirements.txt:

Text

Flask
Flask-SQLAlchemy
psycopg2-binary
    
3
Task
Docker SELF, level 23, lesson 0
Locked
Creating Containers with Docker Compose
Creating Containers with Docker Compose
3
Task
Docker SELF, level 23, lesson 0
Locked
Running a React Application in Docker
Running a React Application in Docker
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION