File size: 2,338 Bytes
c9a0d7c
f3e2c81
3043d49
f3e2c81
 
 
 
 
 
 
 
3feaa19
c9a0d7c
 
 
 
3e4ec57
 
 
 
 
 
 
 
 
 
 
 
 
142afb4
16a80ff
11a0a36
3e4ec57
d27bb04
93487bc
 
4bc177b
d27bb04
55892b8
9529279
 
 
 
11a0a36
 
549dd8e
11a0a36
549dd8e
 
 
 
 
55892b8
 
d2cdd68
3e4ec57
 
 
f3e2c81
11a0a36
d2cdd68
549dd8e
3e4ec57
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
# Use the official Ubuntu image as a base
FROM ubuntu:latest

# Install necessary packages
RUN apt-get update && \
    apt-get install -y \
    nginx \
    mariadb-server \
    mariadb-client \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create a new user with a unique user ID and group ID
# Check if user/group exists before creating
RUN if ! getent group 1000 >/dev/null; then groupadd -g 1000 user; fi && \
    if ! id -u 1000 >/dev/null 2>&1; then useradd -m -u 1000 -g user user; fi

# Switch to the "user" user
USER user

# Set home to the user's home directory and configure environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Switch to root to perform system-level configurations
USER root

# Create necessary directories and set permissions for Nginx
RUN mkdir -p /var/lib/nginx/body /var/lib/nginx/proxy /var/log/nginx /run/nginx && \
    chmod -R 777 /var/lib/nginx /var/log/nginx /run/nginx

# Create log files with correct permissions
RUN touch /var/log/nginx/access.log /var/log/nginx/error.log && \
    chmod 777 /var/log/nginx/access.log /var/log/nginx/error.log

# Add custom Nginx configuration
RUN echo 'events {' > /etc/nginx/nginx.conf && \
    echo '    worker_connections 1024;' >> /etc/nginx/nginx.conf && \
    echo '}' >> /etc/nginx/nginx.conf && \
    echo 'http {' >> /etc/nginx/nginx.conf && \
    echo '    access_log /var/log/nginx/access.log;' >> /etc/nginx/nginx.conf && \
    echo '    error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
    echo '    server {' >> /etc/nginx/nginx.conf && \
    echo '        listen 8080;' >> /etc/nginx/nginx.conf && \
    echo '        server_name localhost;' >> /etc/nginx/nginx.conf && \
    echo '        location / {' >> /etc/nginx/nginx.conf && \
    echo '            root /var/www/html;' >> /etc/nginx/nginx.conf && \
    echo '            index index.html;' >> /etc/nginx/nginx.conf && \
    echo '        }' >> /etc/nginx/nginx.conf && \
    echo '    }' >> /etc/nginx/nginx.conf && \
    echo '}' >> /etc/nginx/nginx.conf

# Revert to user for application-specific operations
USER user

# Expose ports
EXPOSE 8080 3306

# Start MariaDB and Nginx services
CMD ["sh", "-c", "sudo mysqld_safe & nginx -g 'daemon off;'"]