Skip to content

Instantly share code, notes, and snippets.

@jthorniley
Created January 9, 2020 07:00
Show Gist options
  • Save jthorniley/fba81c62a9d45c723777c7205ff96481 to your computer and use it in GitHub Desktop.
Save jthorniley/fba81c62a9d45c723777c7205ff96481 to your computer and use it in GitHub Desktop.
Install Poetry in Docker devcontainer
USER vscode
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version=0.12.17
ENV PATH "/home/vscode/.poetry/bin:$PATH"
@gpyga
Copy link

gpyga commented Feb 4, 2022

for poetry version >= 1.1.7:

curl -sSL https://install.python-poetry.org | python3 -

@bearrito
Copy link

This is an old post, but how do you have your poetry workflow inside the app?
Where do you call poetry update? How are you handling the interpreter/pylint/pylance path issues?

@gpyga
Copy link

gpyga commented Mar 11, 2022

@bearrito
What I do is I set the config to create the virtualenv in the project directory, which also makes it no longer ephemeral with the container.
You can accomplish this using RUN /home/vscode/.local/bin/poetry config virtualenvs.in-project true. I just find it easier for my workflow to have the environment in project tree.

poetry update is then called in the terminal on vscode. As for dealing with the interpreter and whatnot, because the virtualenv is inside the project, there is a clear path for it in /workspace/vscode/[project]/.venv/bin/[util] which you can set in your .vscode/settings.json or in .devcontainer/devcontainer.json.

I've seen people set virtualenvs.create false and then use RUN /home/vscode/.local/bin/poetry install in the Dockerfile too. I would imagine that would get rid of the need to separately set the location of your paths. If you want to avoid having to specify all of the path for each time you run poetry in your Dockerfile, I believe you should be able to accomplish that via multi-stage builds, but I am a creature of habit and never tried it.

@georg-wolflein
Copy link

You can set "postCreateCommand": "poetry update" in .devcontainer/devcontainer.json.

@joarobles
Copy link

You could also set the variable in the local poetry config file poetry.toml:

[virtualenvs]
in-project = true

Or using the CLI:

poetry config virtualenvs.in-project true --local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment