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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -25
Dockerfile CHANGED
@@ -1,35 +1,28 @@
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
-
 
1
+ # Use the official Python 3.9 image
 
 
 
2
  FROM python:3.9
3
+
4
+ # Set the working directory to /code
5
  WORKDIR /code
6
+
7
+ # Copy the current directory contents into the container at /code
8
  COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install requirements.txt
11
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
 
 
14
  RUN useradd -m -u 1000 user
15
+ # Switch to the "user" user
16
  USER user
17
+ # Set home to the user's home directory
18
  ENV HOME=/home/user \\
19
  PATH=/home/user/.local/bin:$PATH
20
+
21
+ # Set the working directory to the user's home directory
22
  WORKDIR $HOME/app
23
+
24
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
25
  COPY --chown=user . $HOME/app
26
+
27
+ # Start the FastAPI app on port 7860, the default port expected by Spaces
28
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]