我对编程很陌生,在尝试lauch时出错
fastapi
具有的项目
Docker
和
Poetry
.
以下是我的项目结构:
.
âââ backend
â  âââ Dockerfile
â  âââ poetry.lock
â  âââ pyproject.toml
â  âââ src
â  â  âââ domain
â  â  â  âââ __init__.py
â  â  âââ infrastructure
â  â  â  âââ __init__.py
â  â  âââ __init__.py
â  â  âââ presentation
â  â  âââ __init__.py
â  â  âââ main.py
â  âââ tests
â  âââ __init__.py
âââ docker-compose.yaml
âââ README.md
这是Docker文件:
FROM python:3.11-slim
WORKDIR /backend
COPY . /backend
RUN pip install --upgrade pip && pip install poetry
RUN poetry install
EXPOSE 8000
和docker-compose.yaml:
services:
# PostgreSQL
db:
image: postgres
restart: always
env_file:
- backend/.env
ports:
- '5432:5432'
healthcheck:
test: [ "CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'" ]
interval: 10s
timeout: 3s
retries: 3
# BackEnd
backend:
build:
context: backend
command: bash -c 'uvicorn src.presentation.main:app --host 0.0.0.0 --port 8000 --reload'
ports:
- '8000:8000'
volumes:
- .:/backend
restart: always
depends_on:
db:
condition: service_healthy
我的
pyproject.toml
:
[tool.poetry]
name = "startup"
version = "0.1.0"
description = ""
authors = ["RRoxxxsii <[email protected]>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
fastapi = {extras = ["all"], version = "^0.109.0"}
pytest="^7.4.4"
pytest-asyncio = "^0.23.3"
pre-commit = "^3.6.0"
sqlalchemy = "^2.0.25"
alembic = "^1.13.1"
uvicorn = "^0.25.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
当我开始项目时
docker compose up
我得到错误:
bash: line 1: uvicorn: command not found
我也不明白为什么
uvicorn
在poetry.lock和pyproject.toml内部