英文:
setting up docker with python 3.9 + poetry getting 'does not contain any element'
问题
I am trying to setup docker for local dev and i keep getting "does not contain any element" when i try to use poetry with docker. Originally I used the requirement.txt, however i would prefer it to have poetry because where i work we have a pyserver which we need to pull some of the .wh from.
So i am trying to keep it basic. This my structure and some basic code
-------------------main.py-------------
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, World!"}
----------------------uvicorn_conf.py------
from uvicorn.workers import UvicornWorker
bind = "0.0.0.0:8000"
workers = 4
worker_class = UvicornWorker
-----------Dockerfile-------
FROM python:3.9
# Set the working directory to /app
WORKDIR /app
# Copy the entire project directory to the container
COPY . .
# Install Poetry and project dependencies
RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
# Start the server
CMD ["poetry", "run", "start"]
---------pyproject.toml------
[tool.poetry]
name = "my-app"
version = "0.1.0"
description = ""
authors = ["py_dev <test@testing.com>"]
readme = "README.md"
packages = [{include = "my_app"}]
[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.95.1"
uvicorn = "^0.21.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
start = "uvicorn my_app.main:app --config uvicorn_conf.py"
英文:
I am trying to setup docker for local dev and i keep getting "does not contain any element" when i try to use poetry with docker. Originally I used the requirement.txt, however i would prefer it to have poetry because where i work we have a pyserver which we need to pull some of the .wh from.
So i am trying to keep it basic. This my structure and some basic code
-------------------main.py-------------
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, World!"}
----------------------uvicorn_conf.py------
from uvicorn.workers import UvicornWorker
bind = "0.0.0.0:8000"
workers = 4
worker_class = UvicornWorker
-----------Dockerfile-------
FROM python:3.9
# Set the working directory to /app
WORKDIR /app
# Copy the entire project directory to the container
COPY . .
# Install Poetry and project dependencies
RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
# Start the server
CMD ["poetry", "run", "start"]
---------pyproject.toml------
[tool.poetry]
name = "my-app"
version = "0.1.0"
description = ""
authors = ["py_dev <test@testing.com>"]
readme = "README.md"
packages = [{include = "my_app"}]
[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.95.1"
uvicorn = "^0.21.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
start = "uvicorn my_app.main:app --config uvicorn_conf.py"
And every time i run build, I get this error.
I am not sure how to fix this. Any advice or direction on how to get it working would be brilliant. Thank you in advance.
答案1
得分: 1
没有在您发布的截图中找到“my_app”目录,所以您应该在您的pyproject.toml
文件中将"my_app"
更新为"app"
:
packages = [{include = "app"}]
更多信息,请参见https://python-poetry.org/docs/pyproject/#packages。
英文:
There's no "my_app" directory in the screenshot you posted, so you should update "my_app"
to "app"
in your pyproject.toml
:
packages = [{include = "app"}]
See https://python-poetry.org/docs/pyproject/#packages for more info.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论