Andreas
Andreas

Reputation: 9207

Poetry add dependency within docker-compose

I am new to docker and poetry but are currently working in a project which contains both.

Problem:

I am unable to add new dependencies via poetry to the docker-compose container.

Description:

In pycharm I use docker-compose as my interpreter for a django project where poetry is used to manage the dependencies. I can access the django-project via localhost, so it seems to work.

What I tried:

The poetry documentation states the following example:

poetry add requests pendulum

But when I execute this command in the pycharm terminal it states, that python wasn't found. My expectation was that I can install a dependency via the CLI which is then managed by poetry and the poetry.lock and pyproject.toml are then updated.

Question:

How can I add new dependencies, or even access the CLI within docker compose to execute the above command?

Update:

I was able to install the dependency by:

writing in the terminal:

  1. docker compose down
  2. inserting dependency into the pyproject.toml
  3. docker compose run --rm django poetry lock --no-update
  4. docker compose build django

But still unable to access a CLI where I can execute poetry commands directly.

Upvotes: 1

Views: 672

Answers (1)

safhac
safhac

Reputation: 1149

hi this is pretty old but you should use the Dockerfile i.e RUN poetry add.. the dockerfile can be specified within compose

Upvotes: 0

Related Questions