Add fastapi on the awesome-compose project
Signed-off-by: vjanz <valon.januzaj98@gmail.com>
This commit is contained in:
parent
e07a341493
commit
33960f9678
12
fastapi/Dockerfile
Normal file
12
fastapi/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
FROM python:3.8
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apt update
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["uvicorn", "--host", "0.0.0.0", "--port", "8000", "src.app:app"]
|
55
fastapi/README.md
Normal file
55
fastapi/README.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
## Compose sample application
|
||||||
|
### Python/FastAPI application
|
||||||
|
|
||||||
|
Project structure:
|
||||||
|
```
|
||||||
|
.
|
||||||
|
├── docker-compose.yaml
|
||||||
|
├── Dockerfile
|
||||||
|
├── requirements.txt
|
||||||
|
├── src
|
||||||
|
├── app.py
|
||||||
|
├── __init__.py
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
[_docker-compose.yaml_](docker-compose.yaml)
|
||||||
|
```
|
||||||
|
version: '3.7'
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: fastapi-service
|
||||||
|
ports:
|
||||||
|
- '8000:8000'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deploy with docker-compose
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
## Expected result
|
||||||
|
|
||||||
|
Listing containers must show one container running and the port mapping as below:
|
||||||
|
```
|
||||||
|
$ docker ps
|
||||||
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
|
69893120c355 fastapi_api "uvicorn --host 0.0.…" About a minute ago Up About a minute 0.0.0.0:8000->8000/tcp fastapi-service
|
||||||
|
```
|
||||||
|
|
||||||
|
After the application starts, navigate to `http://localhost:8000` in your web browser and you should see the following json response:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"message": "OK"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Stop and remove the containers
|
||||||
|
```
|
||||||
|
$ docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
|
9
fastapi/docker-compose.yml
Normal file
9
fastapi/docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
version: '3.7'
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: fastapi-service
|
||||||
|
ports:
|
||||||
|
- '8000:8000'
|
2
fastapi/requirements.txt
Normal file
2
fastapi/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fastapi
|
||||||
|
uvicorn
|
0
fastapi/src/__init__.py
Normal file
0
fastapi/src/__init__.py
Normal file
11
fastapi/src/app.py
Normal file
11
fastapi/src/app.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
app = FastAPI(debug=True)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def hello_world():
|
||||||
|
return {"message": "OK"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user