Git Product home page Git Product logo

poetry-fastapi-docker's Introduction

Poetry - FastAPI - Docker

Note I currently do not actively use or maintain this project, the versions of Debian, Python and Poetry are not up to date!

Table Of Contents

About The Project

This repo serves as a minimal reference on setting up docker multi-stage builds with poetry.

This is an updated and modified fork of python-poetry-docker-example.

Note - This is only tested with Linux and macOS

Differences

  • Newer poetry version
  • Install poetry from python-poetry GitHub source
  • Does not run production image as /root
  • Set the SHELL option -o pipefail before RUN with a pipe

Requirements

NOTE - Run all commands from the project root

Local development

Poetry

Create the virtual environment and install dependencies with:

poetry install

See the poetry docs for information on how to add/update dependencies.

Run commands inside the virtual environment with:

poetry run <your_command>

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/

To run testing/linting locally you would run lint/test in the scripts directory.

Docker

Build images with:

docker build -t poetry-project .

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 -t poetry-project --target $STAGE .

For example we wanted to stop at the test stage:

docker build -t poetry-project --target test .

We could then get a shell inside the container with:

docker run -it poetry-project 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.

Run the 'production' image:

docker run -it -p 8000:8000 poetry-project

Open your browser and go to http://localhost:8000/redoc to see the API spec in ReDoc.

Docker Compose

You can build and run the container with Docker Compose

docker compose up

Or, run in detached mode if you prefer.

NOTE - If you use an older version of Docker Compose, you may need to uncomment the version in the docker-compose,yml file!

Credits

poetry-fastapi-docker's People

Contributors

dependabot[bot] avatar svx avatar unredundant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

poetry-fastapi-docker's Issues

docker run breaks

When I use any docker run commands, like docker run -it poetry-project:latest bash
I get the error bash: 1: /docker-entrypoint.sh: not found which is strange since I see the file copied in the Dockerfile
COPY ./docker/docker-entrypoint.sh /docker-entrypoint.sh

Building fails

$ docker build --tag poetry-project --file docker/Dockerfile.Local .

Output:

[+] Building 0.1s (2/2) FINISHED
 => [internal] load build definition from Dockerfile.Local                                                                                              0.0s
 => => transferring dockerfile: 3.41kB                                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                                       0.0s
 => => transferring context: 35B                                                                                                                        0.0s
failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 102: unknown instruction: /GUNICORN_CONF.PY

Make new release

  • Tag current main branch as 0.1 release and create a GitHub release
  • Add Changelog to updates branch
  • Merge updates branch, tag as 0.2 and make GitHub release
  • Add GitHub templates for PRs and issues

docker-entrypoint.sh: not found

Thanks for sharing this project!

For me, running the commands as described in the Readme results in error /docker-entrypoint.sh: not found when launching docker run

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.