Git Product home page Git Product logo

fastapi-in-docker-example's Introduction

FastAPI in Docker example

From FastAPI site

Docker is a software platform that allows you to build, test, and deploy applications quickly.
Docker packages software into standardized units called containers that have everything
the software needs to run including libraries, system tools, code, and runtime.

Project structure

    ├── app
    │   ├── __init__.py
    │   └── app.py
    ├── .gitignore
    ├── Dockerfile
    ├── README.md
    ├── main.py
    └── requirements.txt

Without docker

Setup the project

pip install -r requirements.txt

Run

uvicorn main:app --host 0.0.0.0 --port 8000

Check

  1. http://127.0.0.1:8000/
Hello	"FastApi in Docker test"
  1. http://127.0.0.1:8000/items/5?q=somequery
item_id	5
q	"somequery"
  1. http://127.0.0.1:8000/docs

Docker

Maybe run as sudo

Build

docker build -t fastdoc .

Run

docker run -d --name fastdoc -p 80:80 fastdoc

docker container stop fastdoc
fastdoc

docker container sart fastdoc
fastdoc

Check

  1. http://127.0.0.1/
Hello	"FastApi in Docker test"
  1. http://127.0.0.1/items/5?q=somequery
item_id	5
q	"somequery"
  1. http://127.0.0.1/docs

Some useable Docker commands

  1. View image:
docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
fastdoc       latest    177ca8c9a42c   6 seconds ago   868MB
  1. View container:
docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS
02aada22a754   fastdoc   "uvicorn app.app:app…"   20 seconds ago   Up 19 seconds
  1. Remove container:
docker container rm fastdoc
fastsoc
  1. Remove image:
docker image rm fastdoc
Untagged: fastdoc:latest
Deleted: sha256:177ca8c9

fastapi-in-docker-example's People

Contributors

antoniokolosov avatar

Watchers

 avatar

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.