File size: 2,166 Bytes
9c087ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Use latest Alpine as base image
FROM alpine:latest

# Maintainer info
LABEL maintainer="you@example.com"

# Enable Alpine edge community repo for dotnet8 packages
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    apk update

# Install necessary packages: dotnet8-runtime, aspnetcore8-runtime, supervisor, and nginx
RUN apk add --no-cache \
    tar \
    wget \
    nginx \
    tzdata \
    supervisor \
    dotnet8-runtime \
    aspnetcore8-runtime 

# Create a non-root user and group
RUN addgroup -S app_admin && adduser -S app_user -G app_admin

# Set environment variables
ENV HOME=/home/app_user \
    PATH=/home/app_user/.local/bin:$PATH

# Create necessary directories with proper permissions
RUN mkdir -p /app /app/dns-server /opt/technitium/dns /var/log /var/lib/logs /tmp && \
    touch /app/supervisord.log /app/supervisord.pid /app/nginx.pid && \
    chmod 777 /app/supervisord.log /app/supervisord.pid /app/nginx.pid && \
    chown -R app_user:app_admin /app /var/log /var/lib/logs/  /tmp && \
    chmod -R 755 /app /tmp && \
    chmod -R 777 /var/log 

RUN mkdir -p /var/log/nginx /run/nginx  && \
    chown -R app_user:app_admin /var/lib/nginx /var/log/nginx  

# Copy the application files into the container with proper ownership
COPY --chown=app_user:app_admin . $HOME/app 

# Copy the Nginx configuration file
COPY --chown=app_user:app_admin ./nginx.conf /etc/nginx/conf.d/nginx.conf
COPY --chown=app_user:app_admin ./nginx.conf /etc/nginx/nginx.conf

# Copy the supervisord configuration file
COPY --chown=app_user:app_admin ./supervisord.conf /etc/supervisord.conf

# Download Technitium DNS Server and extract
RUN wget https://download.technitium.com/dns/DnsServerPortable.tar.gz -O /tmp/DnsServerPortable.tar.gz && \
    mkdir -p /app/dns-server && \
    tar -zxf /tmp/DnsServerPortable.tar.gz -C /app/dns-server && \
    rm -rf /tmp/DnsServerPortable.tar.gz

# Set working directory for DNS Server
WORKDIR /app

# Expose the necessary ports
EXPOSE 7860

# Switch to non-root user
USER app_user

# Start Supervisor to manage services
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]