HussainM899 commited on
Commit
f9b5984
1 Parent(s): be5ddbd

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +64 -0
Dockerfile ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1
2
+
3
+ # Base image using the specified Python version
4
+ ARG PYTHON_VERSION=3.12.2
5
+ FROM python:${PYTHON_VERSION}-slim as base
6
+
7
+ # Prevents Python from writing pyc files.
8
+ ENV PYTHONDONTWRITEBYTECODE=1
9
+
10
+ # Install TensorFlow 2.0
11
+ RUN pip install tensorflow==2.16.1
12
+
13
+ # Install tf-keras package to resolve the missing dependency
14
+ RUN pip install tf-keras
15
+
16
+ # Keeps Python from buffering stdout and stderr to avoid situations where
17
+ # the application crashes without emitting any logs due to buffering.
18
+ ENV PYTHONUNBUFFERED=1
19
+
20
+ WORKDIR /app
21
+
22
+ # Create a non-privileged user that the app will run under.
23
+ # See https://docs.docker.com/go/dockerfile-user-best-practices/
24
+ ARG UID=10001
25
+ RUN adduser \
26
+ --disabled-password \
27
+ --gecos "" \
28
+ --home "/nonexistent" \
29
+ --shell "/sbin/nologin" \
30
+ --no-create-home \
31
+ --uid "${UID}" \
32
+ appuser
33
+
34
+ # Download dependencies as a separate step to take advantage of Docker's caching.
35
+ # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
36
+ # Leverage a bind mount to requirements.txt to avoid having to copy them into
37
+ # into this layer.
38
+ RUN --mount=type=cache,target=/root/.cache/pip \
39
+ --mount=type=bind,source=requirements.txt,target=requirements.txt \
40
+ python -m pip install -r requirements.txt
41
+
42
+ # Switch to the non-privileged user to run the application.
43
+ USER appuser
44
+
45
+ # Set the TRANSFORMERS_CACHE environment variable
46
+ ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface
47
+
48
+ # Create the cache folder with appropriate permissions
49
+ RUN mkdir -p $TRANSFORMERS_CACHE && chmod -R 777 $TRANSFORMERS_CACHE
50
+
51
+ # Set NLTK data directory
52
+ ENV NLTK_DATA=/tmp/nltk_data
53
+
54
+ # Create the NLTK data directory with appropriate permissions
55
+ RUN mkdir -p $NLTK_DATA && chmod -R 777 $NLTK_DATA
56
+
57
+ # Copy the source code into the container.
58
+ COPY . .
59
+
60
+ # Expose the port that the application listens on.
61
+ EXPOSE 8000
62
+
63
+ # Run the application.
64
+ CMD uvicorn 'main:app' --host=0.0.0.0 --port=8000