dsmueller commited on
Commit
72143fc
1 Parent(s): 28651fd

Update Dockerfile to set up user permissions and working directory

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -10
Dockerfile CHANGED
@@ -1,20 +1,29 @@
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.11.5-bookworm
3
 
4
- # Create the directory (if it doesn't already exist)
5
- RUN mkdir -p /usr/src/app
 
6
 
7
- # Change permissions for /usr/src/app to read/write/execute
8
- RUN chmod -R 777 /usr/src/app
9
 
10
- # Set the working directory in the container
11
- WORKDIR /usr/src/app
 
 
 
 
 
 
 
 
12
 
13
  # Install poetry
14
  RUN pip3 install poetry
15
 
16
  # Copy only the necessary files for installing dependencies
17
- COPY pyproject.toml poetry.lock ./
18
 
19
  # Disable virtual environments creation by Poetry
20
  # as the Docker container itself is an isolated environment
@@ -24,8 +33,8 @@ RUN poetry config virtualenvs.create false
24
  # RUN pip3 install -r requirements.txt
25
  RUN poetry install
26
 
27
- # Copy the current directory contents into the container at /usr/src/app
28
- COPY . .
29
 
30
  # Make a port available to the world outside this container
31
  # The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. Your container needs to listen to Streamlit’s (default) port 8501.
@@ -35,7 +44,7 @@ EXPOSE 8501
35
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
36
 
37
  # Update working directory to be consistent with where Start.py is
38
- WORKDIR /usr/src/app/scripts
39
 
40
  # An ENTRYPOINT allows you to configure a container that will run as an executable. Here, it also contains the entire streamlit run command for your app, so you don’t have to call it from the command line
41
  ENTRYPOINT ["streamlit", "run", "Start.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.11.5-bookworm
3
 
4
+ # The next few lines come from here: https://huggingface.co/docs/hub/spaces-sdks-docker#permissions
5
+ # Set up a new user named "user" with user ID 1000
6
+ RUN useradd -m -u 1000 user
7
 
8
+ # Switch to the "user" user
9
+ USER user
10
 
11
+ # Set home to the user's home directory
12
+ ENV HOME=/home/user \
13
+ PATH=/home/user/.local/bin:$PATH
14
+
15
+ # Change permissions for to read/write/execute
16
+ RUN mkdir -p $HOME/app
17
+ RUN chmod 777 $HOME/app
18
+
19
+ # Set the working directory to the user's home directory
20
+ WORKDIR $HOME/app
21
 
22
  # Install poetry
23
  RUN pip3 install poetry
24
 
25
  # Copy only the necessary files for installing dependencies
26
+ COPY --chown=user pyproject.toml poetry.lock ./
27
 
28
  # Disable virtual environments creation by Poetry
29
  # as the Docker container itself is an isolated environment
 
33
  # RUN pip3 install -r requirements.txt
34
  RUN poetry install
35
 
36
+ # Copy the current directory contents into the container
37
+ COPY --chown=user . $HOME/app
38
 
39
  # Make a port available to the world outside this container
40
  # The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. Your container needs to listen to Streamlit’s (default) port 8501.
 
44
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
45
 
46
  # Update working directory to be consistent with where Start.py is
47
+ WORKDIR $HOME/app/scripts
48
 
49
  # An ENTRYPOINT allows you to configure a container that will run as an executable. Here, it also contains the entire streamlit run command for your app, so you don’t have to call it from the command line
50
  ENTRYPOINT ["streamlit", "run", "Start.py", "--server.port=8501", "--server.address=0.0.0.0"]