File size: 1,220 Bytes
2d67d84
 
 
08e27d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0aa5c09
d0e3dc8
08e27d8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Use an Nginx base image
FROM nginx:alpine

# Create non-root user first
RUN adduser -D -u 1000 user

# Create required nginx directories with correct permissions
RUN mkdir -p /tmp/nginx/cache \
    /tmp/nginx/run \
    /tmp/nginx/client_temp \
    /tmp/nginx/proxy_temp \
    /tmp/nginx/fastcgi_temp \
    /tmp/nginx/uwsgi_temp \
    /tmp/nginx/scgi_temp && \
    chown -R user:user /tmp/nginx

# Set up the web root directory with correct permissions
RUN mkdir -p /usr/share/nginx/html && \
    chown -R user:user /usr/share/nginx/html

# Copy web files and set ownership
COPY --chown=user web /usr/share/nginx/html

# Set up user's home directory
WORKDIR /home/user/app
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Copy application files
COPY --chown=user . /home/user/app

# Switch to non-root user
USER user

# Nginx configurations remain accessible to root
RUN echo $'server {\n\
    listen 7860;\n\
    location / {\n\
        root   /usr/share/nginx/html;\n\
        index  index.html index.htm;\n\
        try_files $uri $uri/ /index.html;\n\
    }\n\
}\n' > /tmp/nginx.conf

# Use unprivileged port 7860
EXPOSE 7860

# Start Nginx with the custom config
CMD ["nginx", "-c", "/tmp/nginx.conf"]