https://github.com/hendrapaiton/container
Fastapi and MongoDB Container using Podman
https://github.com/hendrapaiton/container
fastapi httpx mongodb podman pytest uvicorn
Last synced: about 2 months ago
JSON representation
Fastapi and MongoDB Container using Podman
- Host: GitHub
- URL: https://github.com/hendrapaiton/container
- Owner: hendrapaiton
- License: mit
- Created: 2021-08-04T01:10:54.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-04T19:26:24.000Z (almost 5 years ago)
- Last Synced: 2025-02-22T20:47:48.485Z (over 1 year ago)
- Topics: fastapi, httpx, mongodb, podman, pytest, uvicorn
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CONTAINER MANAGEMENT USING PODMAN
## Create FastAPI Application
First, create simple application with fastapi.
```python
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"pesan": "Halo Dunia"}
```
## Create Containerfile for fastapi
Create Containerfile.
```
FROM python:3.8.5-alpine
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /app/requirements.txt
RUN set -eux \
&& apk add --no-cache --virtual .build-deps build-base libressl-dev libffi-dev gcc musl-dev python3-dev \
&& pip install --upgrade pip setuptools wheel \
&& pip install -r /app/requirements.txt \
&& rm -rf /root/.cache/pip
COPY . /app/
```
## Build and Deploy container using Podman
When Containerfile already created, now build images of fastapi application.
```bash
$ podman build -t fastapi .
```
Check if images successfully created.
```bash
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/fastapi latest b6e2a7315140 17 seconds ago 520 MB
docker.io/library/python 3.8.5-alpine 0f03316d4a27 10 months ago 44.7 MB
```
And then deploy the image to container.
```bash
$ podman run -dt -p 8000:8000/tcp localhost/fastapi
```
Finally check if container already run.
```bash
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f7474cd97c5 localhost/fastapi:latest uvicorn server.ap... 52 seconds ago Up 51 seconds ago 0.0.0.0:8000->8000/tcp nervous_galois
```
## Testing application in container
Testing url of container using curl.
```bash
$ curl localhost:8000
{"pesan": "Halo Dunia"}
```
---
### Reference
[Fastapi Tutorial](https://fastapi.tiangolo.com/tutorial/first-steps/)
[Podman Container Tutorial](https://podman.io/getting-started/)
[Podman Pod Tutorial](https://developers.redhat.com/blog/2019/01/15/podman-managing-containers-pods#pods_and_container_management)