omarkham commited on
Commit
7bc0f18
·
1 Parent(s): cc47fc6

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -0
Dockerfile CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Dockerfile sets up a Python 3.9 environment, installs the packages
2
+ #listed in requirements.txt, and starts a FastAPI app on port 7860
3
+
4
+ #We're going to use the Python 3.9 Docker Image as the base image for our container
5
+ FROM python:3.9
6
+
7
+ #Sets the working directory inside the container to '/code'
8
+ WORKDIR /code
9
+
10
+ #Copies the requirements.txt file from our local directory to the '/code' directory inside the container
11
+ COPY ./requirements.txt /code/requirements.txt
12
+
13
+ #Use pip to install the packages and to not use any cached packages, and to upgrade any packages.
14
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
15
+
16
+ #Creates a new user with user ID of 1000, switches to that user and then sets the home directory to '/home/user'
17
+ #The ENV command sets the HOME and PATH environment variables.
18
+ #PATH is modified to include the '.local/bin' directory in the user's home directory so that anyt binaries installed by pip will be available on the command line
19
+ RUN useradd -m -u 1000 user
20
+ USER user
21
+ ENV HOME=/home/user \\
22
+ PATH=/home/user/.local/bin:$PATH
23
+
24
+ #Sets the working directory inside the container to $HOME/app, which is '/home/user/app'
25
+ WORKDIR $HOME/app
26
+
27
+ #Copies the contents of our local directory into the '/home/user/app' directory inside the container, setting the owner of the files to the user we created earlier
28
+ COPY --chown=user . $HOME/app
29
+
30
+ #Specifies the command to run when the container starts
31
+ #Starts the FastAPI app using uvicorn and listens on port 7860
32
+ #The '--host' flage specifies that the app should listen on all available network interfaces
33
+ #The 'app:app' argument tells 'uvicorn' to look for the app object in the app module in our code
34
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
35
+