Poetry not installing current project in docker build #9907
-
Hi, need some help. I have a poetry project that runs well locally. When I do This is my [tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
readme = "README.md"
packages = [{include = "my_module"}]
[tool.poetry.dependencies]
python = "^3.13"
boto3 = "^1.35.78"
motor = "^3.6.0"
pymysql = "^1.1.1"
types-pymysql = "^1.1.0.20241103"
openai = "^1.57.4"
numpy = "^2.2.0"
[tool.poetry.group.dev.dependencies]
ruff = "^0.8.2"
mypy = "^1.13.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api" And this is my Docker file: ROM public.ecr.aws/docker/library/python:3.13-slim
RUN apt-get update \
&& apt-get install -y curl build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sSL https://install.python-poetry.org | python -
ENV PATH="/root/.local/bin:$PATH"
WORKDIR /app
COPY my-project/pyproject.toml my-project/poetry.lock ./
RUN poetry config virtualenvs.create false \
&& poetry install --without dev
COPY my-project/* ./my-project/
CMD ["poetry", "run", "python", "my_module/app.py"] Any help from someone with experience with using docker and Poetry would be much appreciated. Ideally I want to keep my module as an installed to make testing and CI easier down the line. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
i had to replace |
Beta Was this translation helpful? Give feedback.
-
You need Then once that is complete and you copy over the source tree, run install again without the |
Beta Was this translation helpful? Give feedback.
-
Thanks for responding guys. I actually got it working like this: FROM public.ecr.aws/docker/library/python:3.11-slim
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential curl \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sSL https://install.python-poetry.org | python - \
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry
ENV PATH="/root/.local/bin:$PATH"
COPY my-project/pyproject.toml my-project/poetry.lock ./
COPY my-project/my_module ./my_module
RUN poetry config virtualenvs.create false \
&& poetry install --without dev
CMD ["poetry", "run", "python", "my_module/app.py"] So:
Mysteriously, if I don't separate out the two copy steps like that the install fails. @abn What's the advantage of doing the install in two steps like that without the root and then for the root? I've seen people do this elsewhere too. -> EDIT: Ignore me sorry I didn't read your answer fully |
Beta Was this translation helpful? Give feedback.
i had to replace
COPY my-project/pyproject.toml my-project/poetry.lock ./
with
COPY . ./