DATABASE_URL = "postgresql+asyncpg://postgres:postgres@0.0.0.0:5432/postgres"
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@db:5432/postgres"
# Используем базовый образ с Python 3.11-slim-bookworm
FROM python:3.11-slim-bookworm
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false
ENV PATH="${PATH}:/root/.local/bin"
EXPOSE 8000
EXPOSE 5433
RUN apt-get -y update && \
apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
postgresql-client \
libssl-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir poetry
WORKDIR /app
COPY pyproject.toml poetry.lock ./
COPY . .
RUN poetry update # Обновление зависимостей
RUN poetry install --no-root # Установка зависимостей
# Запуск приложения
CMD ["/app/entrypoint.sh"]
version: "3.0"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
volumes:
- .:/app
networks:
- custom
depends_on:
- db
db:
container_name: "db"
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
ports:
- "5433:5432"
networks:
- custom
db_test:
container_name: "db_test"
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_USER=postgres_test
- POSTGRES_PASSWORD=postgres_test
- POSTGRES_DB=postgres_test
ports:
- "5434:5432"
networks:
- custom
networks:
custom:
driver: bridge
#!/bin/sh
alembic -c alembic.ini upgrade heads
poetry run python main.py