Skip to content

LesiaUKR/goit-pythonweb-hw-02

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task 2

Clone a FastAPI application, configure and run it in a Docker container, and check the application's functionality and database connection.

Step-by-Step Instructions

  1. Clone the repository at https://github.com/GoIT-Python-Web/Computer-Systems-hw02 using git clone and navigate to the cloned directory.

  2. Create a Dockerfile with instructions to build the Docker image for the application.

  3. Write a docker-compose.yaml file with the configuration for the application and PostgreSQL.

  4. Use Docker Compose to build the environment and the docker-compose up command to launch the environment.

💡 Hint: Modify the SQLALCHEMY_DATABASE_URL connection string found in conf/db.py. Instead of localhost, insert the PostgreSQL service name from your docker-compose.yaml.

Example:

SQLALCHEMY_DATABASE_URL = f"postgresql+psycopg2://postgres:567234@localhost:5432/hw02"

When using Docker Compose, each service (container) has its own network, and they usually can’t communicate via localhost. Instead, use the service name as the hostname.

  1. Verify the application’s functionality and the database’s availability. 💡 Hint:

After running the container with the application, the browser view should appear as follows:

Container If correctly configured in docker-compose.yaml, pressing the “Check DB” button should display the following:

Container

If you see a red error box instead of “Welcome to FastAPI!”, it means docker-compose.yaml is incorrectly configured.

Acceptance Criteria

  • The repository is cloned, and a Dockerfile for building the application’s Docker image is created.
  • A docker-compose.yaml file is written with configuration for the application and PostgreSQL.
  • Docker Compose and the docker-compose up command are used to build and run the environment.
  • The application is functional, and the database is accessible, as confirmed by pressing the “Check DB” button.

TASK RESULTS

Step 1

Step 2

Step 3

Step 4

About

Master's degree | Advanced Python Programming| HW | DOCKER fundamentals

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published