Skip to content

Commit cdd5d01

Browse files
committed
update docker file
1 parent 3e48610 commit cdd5d01

File tree

1 file changed

+78
-22
lines changed

1 file changed

+78
-22
lines changed

dockerfile

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
# FROM python:3.10-slim
2-
#
3-
# WORKDIR /app
4-
# COPY requirements.txt .
5-
# RUN pip install --no-cache-dir -r requirements.txt
6-
#
7-
# COPY ./app ./app
8-
#
9-
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
1+
# ---------- Script 1 ----------
2+
FROM python:3.10-slim
103

11-
# Stage 1: Build Environment
12-
FROM python:3.10 as builder
134
WORKDIR /app
145
COPY requirements.txt .
15-
RUN pip install --user -r requirements.txt
16-
17-
# Stage 2: Runtime Environment
18-
FROM python:3.10-slim
19-
WORKDIR /app
20-
COPY --from=builder /root/.local /root/.local
21-
COPY . .
6+
RUN pip install --no-cache-dir -r requirements.txt
227

23-
# Ensure scripts in .local are usable
24-
ENV PATH=/root/.local/bin:$PATH
8+
COPY ./app ./app
259

2610
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
11+
# ---------- Script 1 ----------
2712

13+
# ---------- Script 2 ----------
2814
# Stage 1: Build Environment
15+
# FROM python:3.10 as builder
16+
# WORKDIR /app
17+
# COPY requirements.txt .
18+
# RUN pip install --user -r requirements.txt
19+
#
20+
# # Stage 2: Runtime Environment
21+
# FROM python:3.10-slim
22+
# WORKDIR /app
23+
# COPY --from=builder /root/.local /root/.local
24+
# COPY . .
25+
#
26+
# # Ensure scripts in .local are usable
27+
# ENV PATH=/root/.local/bin:$PATH
28+
#
29+
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
30+
# ---------- Script 2 ----------
31+
32+
# ---------- Script 3 ----------
33+
# # Stage 1: Build Environment
2934
# FROM python:3.10-slim as builder
3035
#
3136
# RUN python -m venv /vgarbage
@@ -35,8 +40,8 @@ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
3540
# COPY requirements.txt .
3641
#
3742
# RUN pip install --no-cache-dir -r requirements.txt
38-
39-
# Stage 2: Runtime Environment
43+
#
44+
# # Stage 2: Runtime Environment
4045
# FROM python:3.10-slim
4146
# COPY --from=builder /vgarbage /vgarbage
4247
# ENV PATH="/vgarbage/bin:$PATH"
@@ -47,3 +52,54 @@ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
4752
# RUN rm -rf /root/.cache/pip
4853
#
4954
# CMD [ "uvcorn", "main.app", "--host", "0.0.0.0", "--port", "8123" ]
55+
# ---------- Script 3 ----------
56+
57+
# ---------- Script 7 (Most Optimized) ----------
58+
# # Multi-stage build with dependency optimization
59+
# FROM python:3.10-slim as builder
60+
#
61+
# # Install build dependencies
62+
# RUN apt-get update && \
63+
# apt-get install -y --no-install-recommends gcc && \
64+
# rm -rf /var/lib/apt/lists/*
65+
#
66+
# # Set up working directory
67+
# WORKDIR /app
68+
#
69+
# # Copy requirements and install Python dependencies
70+
# COPY requirements.txt .
71+
# RUN pip install --no-cache-dir -r requirements.txt
72+
#
73+
# # Production stage - minimal image
74+
# FROM python:3.10-slim
75+
#
76+
# # Set environment variables for performance
77+
# ENV PYTHONDONTWRITEBYTECODE=1 \
78+
# PYTHONUNBUFFERED=1 \
79+
# PYTHONPATH=/app
80+
#
81+
# # Create non-root user
82+
# RUN groupadd -r appgroup && \
83+
# useradd -r -g appgroup appuser
84+
#
85+
# # Copy only the necessary Python dependencies
86+
# COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
87+
#
88+
# # Set up working directory
89+
# WORKDIR /app
90+
#
91+
# # Copy only the application code
92+
# COPY ./app ./app
93+
#
94+
# # Change ownership to non-root user
95+
# RUN chown -R appuser:appgroup /app
96+
#
97+
# # Switch to non-root user
98+
# USER appuser
99+
#
100+
# # Expose port
101+
# EXPOSE 8123
102+
#
103+
# # Run application
104+
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
105+
# ---------- Script 7 (Most Optimized) ----------

0 commit comments

Comments
 (0)