Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fastapi with docker compose #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions fastapi-postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Use the official Python image as the base image
FROM python:3.11.5-bullseye

# Install PostgreSQL client
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
curl \
netcat-traditional

# Set the working directory to /app
WORKDIR /app

Expand All @@ -20,11 +27,8 @@ COPY . .
# POSTGRES_HOST=0.0.0.0 \
# POSTGRES_PORT=5432

# Install PostgreSQL client
RUN apt-get update && apt-get install -y postgresql-client

# Expose port 80 for the FastAPI application
EXPOSE 8000

# Start the FastAPI application
CMD ["uvicorn", "application.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD [ "/app/entrypoint.sh" ]
8 changes: 6 additions & 2 deletions fastapi-postgres/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- keploy-network

app:
container_name: fastapi-app
image: fastapi
Expand All @@ -26,4 +26,8 @@ services:
depends_on:
- postgres
networks:
- keploy-network
- keploy-network

networks:
keploy-network:
external: true
10 changes: 10 additions & 0 deletions fastapi-postgres/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

until nc -z -v -w30 postgres 5432
do
echo "Waiting for database connection..."
# wait for 5 seconds before check again
sleep 5
done

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