MuhZainur commited on
Commit
b0f5d04
·
unverified ·
1 Parent(s): 714878e

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -0
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile
2
+
3
+ # 1. Gunakan image dasar Python yang ringan
4
+ FROM python:3.9-slim
5
+
6
+ # 2. Set direktori kerja di dalam container
7
+ WORKDIR /app
8
+
9
+ # 3. Buat pengguna non-root baru bernama "appuser"
10
+ # -m -> buat home directory (/home/appuser)
11
+ # -s /bin/bash -> set shell default
12
+ RUN useradd -m -s /bin/bash appuser
13
+
14
+ # 4. Salin file requirements terlebih dahulu
15
+ COPY ./requirements.txt /app/requirements.txt
16
+
17
+ # 5. Install semua library yang dibutuhkan
18
+ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
19
+
20
+ # 6. Salin sisa kode aplikasi Anda
21
+ # --chown=appuser:appuser -> Ganti kepemilikan file menjadi milik appuser
22
+ COPY --chown=appuser:appuser ./main.py /app/main.py
23
+
24
+ # 7. Ganti pengguna dari root ke appuser
25
+ USER appuser
26
+
27
+ # 8. Buka port yang akan digunakan oleh aplikasi
28
+ # PENTING: Hugging Face Spaces untuk Docker menggunakan port 7860
29
+ EXPOSE 7860
30
+
31
+ # 9. Perintah untuk menjalankan aplikasi saat container dimulai
32
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]