tuanhcmute / Nhom1_CCPTPM

3 stars 0 forks source link

Hoàn thành cấu hình Dockerfile và docker-compose.yml cho project #44

Closed tuanhcmute closed 1 year ago

tuanhcmute commented 1 year ago

Hoàn thành cấu hình Dockerfile và docker-compose.yml cho project

  1. Docker compose
    
    version: '3.8'

services: flask: image: flask-python/api-dashboard:v1.0.0 container_name: flask environment:


2. Dockerfile

Sử dụng một docker có sắn

FROM python:3.9-bullseye

Tạo một folder root cho project

WORKDIR /api-dashboard

Copy file requirements.txt vào folder api-dashboard

COPY requirements.txt .

Install lib

RUN pip install -r requirements.txt COPY ./app ./app

Set env

ENV FLASK_ENV=development ENV FLASK_DEBUG=1 ENV FLASK_APP=app/app.py ENV FLASK_RUN_PORT=50000 ENV FLASK_RUN_HOST=0.0.0.0 ENV SECRET_KEY=your_secret_key ENV MAIL_USERNAME=zzro333@gmail.com ENV MAIL_PASSWORD=wiibdoxuisaydfnb ENV SQLALCHEMY_DATABASE_URI=postgresql://postgres:1@localhost:5433/ApiDashboardDB

CMD [ "flask", "run" ]

mytranchi commented 1 year ago

Tiến hành cấu hình Dockerfile và Docker Compose cho Project

1. Dockerfile
# Sử dụng một docker có sắn
FROM python:3.9-bullseye

# Tạo một folder root cho project
WORKDIR /api-dashboard
# Copy file requirements.txt vào folder api-dashboard
COPY requirements.txt .
# Install lib
RUN pip install -r requirements.txt
COPY ./app ./app
# Set env
ENV FLASK_ENV=development
ENV FLASK_DEBUG=1
ENV FLASK_APP=app/app.py
ENV FLASK_RUN_PORT=50000
ENV FLASK_RUN_HOST=0.0.0.0
ENV SECRET_KEY=your_secret_key
ENV MAIL_USERNAME=zzro333@gmail.com
ENV MAIL_PASSWORD=wiibdoxuisaydfnb
ENV SQLALCHEMY_DATABASE_URI=postgresql://postgres:1@localhost:5433/ApiDashboardDB
CMD [ "flask", "run" ]
2. Docker Compose
version: '3.8'

services:
  flask:
    image: flask-python/api-dashboard:v1.0.0
    container_name: flask
    environment:
      - SQLALCHEMY_DATABASE_URI=postgresql://postgres:1@postgresdb:5433/ApiDashboardDB
    ports:
      - 50001:50000
    depends_on:
      postgres:
        condition: service_healthy
    # networks:
    #   - postgres-python-network

  postgres:
    image: postgres
    restart: always
    container_name: postgresdb
    environment:
      POSTGRES_DB: ApiDashboardDB
      POSTGRES_PASSWORD: 1
      PGPORT: 5433
    ports:
      - 5434:5433
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 1m30s
      timeout: 30s
      retries: 5
      start_period: 30s
    # volumes:
    #   - pgdata-volume:/var/lib/postgresql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8081:8080