1
- # See https://unit.nginx.org/installation/#docker-images
2
-
3
- FROM nginx/unit:1.28.0-python3.10
1
+ FROM python:3.11.1-slim-bullseye
4
2
5
3
ENV PYTHONUNBUFFERED 1
6
-
7
- RUN apt-get update && apt-get install -y python3-pip
8
-
9
- # Build folder for our app, only stuff that matters copied.
10
- RUN mkdir build
11
4
WORKDIR /build
12
5
13
- # Update, install requirements and then cleanup.
14
- COPY ./requirements.txt .
6
+ # Create venv, add it to path and install requirements
7
+ RUN python -m venv /venv
8
+ ENV PATH="/venv/bin:$PATH"
15
9
10
+ COPY requirements.txt .
16
11
RUN pip install -r requirements.txt
17
12
18
- RUN apt-get remove -y python3-pip \
19
- && apt-get autoremove --purge -y \
20
- && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list
13
+ # Install uvicorn server
14
+ RUN pip install uvicorn[standard]
21
15
22
16
# Copy the rest of app
23
- COPY app ./ app
24
- COPY alembic ./ alembic
17
+ COPY app app
18
+ COPY alembic alembic
25
19
COPY alembic.ini .
26
20
COPY pyproject.toml .
21
+ COPY init.sh .
22
+
23
+ # Create new user to run app process as unprivilaged user
24
+ RUN addgroup --gid 1001 --system uvicorn && \
25
+ adduser --gid 1001 --shell /bin/false --disabled-password --uid 1001 uvicorn
27
26
28
- # Nginx unit config and init.sh will be consumed at container startup.
29
- COPY init.sh /docker-entrypoint.d/init.sh
30
- COPY nginx-unit-config.json /docker-entrypoint.d/config.json
31
- RUN chmod a+x /docker-entrypoint.d/init.sh
27
+ # Run init.sh script then start uvicorn
28
+ RUN chown -R uvicorn:uvicorn /build
29
+ CMD bash init.sh && \
30
+ runuser -u uvicorn -- /venv/bin/uvicorn app.main:app --app-dir /build --host 0.0.0.0 --port 8000 --workers 2 --loop uvloop
31
+ EXPOSE 8000
0 commit comments