I’m writing a Python app to connect to a Postgres container using the psycopg2 library
def connect():
load_dotenv()
host = os.getenv('POSTGRESQL_HOST')
port = os.getenv('POSTGRESQL_PORT')
user = os.getenv('POSTGRESQL_USER')
password = os.getenv('POSTGRESQL_PASSWORD')
database = os.getenv('POSTGRESQL_DATABASE')
pool = psycopg2.pool.SimpleConnectionPool(
2, 255, user=user, password=password,
host=host, port=port, database=database)
return pool
Then I write Dockerfile and build it successfully.
Dockerfile:
ARG PYTHON_VERSION=3.12
FROM python:3.12-alpine as base
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY . /app/
RUN apk add --no-cache postgresql-libs &&
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev &&
python -m pip install --no-cache-dir wheel &&
python -m pip install --no-cache-dir -r requirements.txt &&
apk --purge del .build-deps
EXPOSE 443
CMD ["python","/app/telegramBot.py"]
But I meet this error when I run image.
enter image description here
Can someone tell me how to fix?
New contributor
IcyWater is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.