saq1b commited on
Commit
a6e975c
·
verified ·
1 Parent(s): b61cc42

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -5
Dockerfile CHANGED
@@ -1,10 +1,27 @@
1
  FROM nginx:alpine
2
 
3
- # Copy all files to the NGINX html directory
4
- COPY . /usr/share/nginx/html/
5
 
6
- # Set proper permissions
7
- RUN chmod -R 755 /usr/share/nginx/html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Create default.conf for nginx to listen on port 7860 (Hugging Face's default port)
10
  RUN echo 'server { \
@@ -17,8 +34,16 @@ RUN echo 'server { \
17
  } \
18
  }' > /etc/nginx/conf.d/default.conf
19
 
 
 
 
 
 
20
  # Expose port 7860 for Hugging Face Spaces
21
  EXPOSE 7860
22
 
23
- # Start NGINX
 
 
 
24
  CMD ["nginx", "-g", "daemon off;"]
 
1
  FROM nginx:alpine
2
 
3
+ # Set up a new user named "user" with user ID 1000
4
+ RUN adduser -D -u 1000 user
5
 
6
+ # Create necessary directories with proper ownership
7
+ RUN mkdir -p /usr/share/nginx/html && \
8
+ chown -R user:user /usr/share/nginx/html
9
+
10
+ # Switch to the "user" user for operations
11
+ USER user
12
+
13
+ # Set home to the user's home directory
14
+ ENV HOME=/home/user \
15
+ PATH=/home/user/.local/bin:$PATH
16
+
17
+ # Set the working directory
18
+ WORKDIR $HOME/app
19
+
20
+ # Copy files with proper ownership
21
+ COPY --chown=user . $HOME/app
22
+
23
+ # Switch back to root for nginx configuration (required)
24
+ USER root
25
 
26
  # Create default.conf for nginx to listen on port 7860 (Hugging Face's default port)
27
  RUN echo 'server { \
 
34
  } \
35
  }' > /etc/nginx/conf.d/default.conf
36
 
37
+ # Copy files from user's app directory to nginx serving directory
38
+ RUN cp -r $HOME/app/* /usr/share/nginx/html/ && \
39
+ chmod -R 755 /usr/share/nginx/html && \
40
+ chown -R user:user /usr/share/nginx/html
41
+
42
  # Expose port 7860 for Hugging Face Spaces
43
  EXPOSE 7860
44
 
45
+ # Switch back to user for running the service
46
+ USER user
47
+
48
+ # Start NGINX (with a slight modification to run as non-root)
49
  CMD ["nginx", "-g", "daemon off;"]