https://github.com/michaeloliverx/python-poetry-docker-example
Example of integrating Poetry with Docker leveraging multi-stage builds.
https://github.com/michaeloliverx/python-poetry-docker-example
Last synced: 5 days ago
JSON representation
Example of integrating Poetry with Docker leveraging multi-stage builds.
- Host: GitHub
- URL: https://github.com/michaeloliverx/python-poetry-docker-example
- Owner: michaeloliverx
- License: mit
- Created: 2020-03-03T18:30:06.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-05T15:42:05.000Z (11 months ago)
- Last Synced: 2024-07-31T22:43:41.443Z (9 months ago)
- Language: Dockerfile
- Size: 20.5 KB
- Stars: 353
- Watchers: 5
- Forks: 59
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - michaeloliverx/python-poetry-docker-example - Example of integrating Poetry with Docker leveraging multi-stage builds. (Dockerfile)
README
# Poetry managed Python FastAPI application with Docker multi-stage builds
### This repo serves as a minimal reference on setting up docker multi-stage builds with poetry
### Requirements
- [Docker >= 17.05](https://www.python.org/downloads/release/python-381/)
- [Python >= 3.7](https://www.python.org/downloads/release/python-381/)
- [Poetry](https://github.com/python-poetry/poetry)---
**NOTE** - Run all commands from the project root## Local development
---
## PoetryCreate the virtual environment and install dependencies with:
poetry install
See the [poetry docs](https://python-poetry.org/docs/) for information on how to add/update dependencies.
Run commands inside the virtual environment with:
poetry run
Spawn a shell inside the virtual environment with
poetry shell
Start a development server locally
poetry run uvicorn app.main:app --reload --host localhost --port 8000
API will be available at [localhost:8000/](http://localhost:8000/)
Swagger docs at [localhost:8000/docs](http://localhost:8000/docs)
To run testing/linting locally you would execute lint/test in the [scripts directory](/scripts).
---
## Docker
Build images with:
docker build --tag poetry-project --file docker/Dockerfile .The Dockerfile uses multi-stage builds to run lint and test stages before building the production stage. If linting or testing fails the build will fail.
You can stop the build at specific stages with the `--target` option:
docker build --name poetry-project --file docker/Dockerfile . --target
For example we wanted to stop at the **test** stage:
docker build --tag poetry-project --file docker/Dockerfile --target test .
We could then get a shell inside the container with:
docker run -it poetry-project:latest bash
If you do not specify a target the resulting image will be the last image defined which in our case is the 'production' image.