I want to make a container for FastAPI authorization application to learn microservices. I have chosen PostgresSQL as the database and it seems that the build was successful, but now in the container with the application the logs say the same thing (bash: line 1: dev/tcp/posrgres/5432: No such file or directory).
Attaching to authorization_app, posrgres_db
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
posrgres_db |
posrgres_db | PostgreSQL Database directory appears to contain a database; Skipping initialization
posrgres_db |
posrgres_db | 2024-08-13 15:34:35.624 UTC [1] LOG: starting PostgreSQL 16.4 (Debian 16.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
posrgres_db | 2024-08-13 15:34:35.624 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
posrgres_db | 2024-08-13 15:34:35.625 UTC [1] LOG: listening on IPv6 address "::", port 5432
posrgres_db | 2024-08-13 15:34:35.642 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
posrgres_db | 2024-08-13 15:34:35.683 UTC [29] LOG: database system was interrupted; last known up at 2024-08-13 15:34:03 UTC
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
posrgres_db | 2024-08-13 15:34:40.325 UTC [29] LOG: database system was not properly shut down; automatic recovery in progress
posrgres_db | 2024-08-13 15:34:40.362 UTC [29] LOG: invalid record length at 0/1912180: expected at least 24, got 0
posrgres_db | 2024-08-13 15:34:40.362 UTC [29] LOG: redo is not required
posrgres_db | 2024-08-13 15:34:40.408 UTC [27] LOG: checkpoint starting: end-of-recovery immediate wait
posrgres_db | 2024-08-13 15:34:40.499 UTC [27] LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.024 s, sync=0.012 s, total=0.100 s; sync files=2, longest=0.007 s, average=0.006 s; distance=0 kB, estimate=0 kB; lsn=0/1912180, redo lsn=0/1912180
posrgres_db | 2024-08-13 15:34:40.511 UTC [1] LOG: database system is ready to accept connections
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
authorization_app | bash: line 1: dev/tcp/posrgres/5432: No such file or directory
Here is my compose file and Dockerfile
services:
app:
container_name: authorization_app
build: ./
depends_on:
- db
command: bash -c 'while !<dev/tcp/posrgres/5432; do sleep 1; done; uvicorn main:app --host 0.0.0.0 --port 8000'
volumes:
- ./app:/src/app
ports:
- ${APP_HOST_PORT}:8000
restart: always
env_file:
- .env
db:
container_name: posrgres_db
image: postgres
environment:
- POSTGRES_DB=database
- POSTGRES_PASSWORD=mypas
- POSTGRESS_DB_USER=${POSTGRESS_DB_USER}
- POSTGRESS_DB_PASSWORD=${POSTGRESS_DB_PASSWORD}
ports:
- ${POSTGRESS_DB_HOST_PORT}:5432
volumes:
- ./postgres:/var/lib/postgresql/data
restart: always
FROM python:3.10
WORKDIR /src
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY . .
I’m still figuring it out, so it could be a simple mistake.
Here are the directories
Simple code to test the operation in main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def get_home():
return {"message": "Hello World"}