-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
44 lines (34 loc) · 1.39 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This Dockerfile sets up a Debian-based container with Python and PostgreSQL.
# It installs the necessary dependencies, creates a virtual environment, and copies the application code.
# The PostgreSQL database is initialized with a user and a database.
# The container exposes port 8000 and starts the application using uvicorn.
FROM debian:stable-slim
# Set environment variables
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
# Install build dependencies
RUN apt-get update -y
RUN apt-get install -y \
python3 \
python3-pip
RUN apt-get install -y wget
# Install PostgreSQL
RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get -y install postgresql
RUN apt install python3.11-venv -y
WORKDIR /app
COPY requirements.txt .
RUN python3 -m venv venv && . venv/bin/activate && pip install --upgrade pip
RUN /bin/bash -c "source venv/bin/activate && pip install -r requirements.txt"
COPY . .
# start postgresql
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER admin WITH SUPERUSER PASSWORD 'password';" &&\
createdb mydb
# EXPOSE port 8000
EXPOSE 8000
# hop into virtual environment
CMD ["/bin/bash", "-c", "source venv/bin/activate", "&&", "uvicorn", "main:app", "--reload"]