devin15 commited on
Commit
ed64aa9
·
verified ·
1 Parent(s): 6f33329

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +146 -0
Dockerfile ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用Alpine Linux稳定版本作为基础镜像
2
+ FROM alpine:latest
3
+
4
+ # 设置维护者信息
5
+ LABEL maintainer="your-email@example.com"
6
+
7
+ # 设置环境变量
8
+ ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
9
+ ENV PATH=$JAVA_HOME/bin:$PATH
10
+ ENV NGINX_VERSION=1.25.3
11
+
12
+ # 更新包管理器并安装必要的依赖
13
+ RUN apk update && apk upgrade && \
14
+ apk add --no-cache \
15
+ # 基础工具
16
+ curl \
17
+ wget \
18
+ ca-certificates \
19
+ # 编译工具(用于nginx编译)
20
+ build-base \
21
+ pcre-dev \
22
+ zlib-dev \
23
+ openssl-dev \
24
+ # Java 17 OpenJDK
25
+ openjdk17-jdk \
26
+ # 清理缓存
27
+ && rm -rf /var/cache/apk/*
28
+
29
+ # 创建nginx用户和组
30
+ RUN addgroup -g 101 -S nginx && \
31
+ adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx
32
+
33
+ # 下载并编译安装nginx主线版本
34
+ RUN cd /tmp && \
35
+ wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
36
+ tar -xzf nginx-${NGINX_VERSION}.tar.gz && \
37
+ cd nginx-${NGINX_VERSION} && \
38
+ ./configure \
39
+ --prefix=/etc/nginx \
40
+ --sbin-path=/usr/sbin/nginx \
41
+ --modules-path=/usr/lib/nginx/modules \
42
+ --conf-path=/etc/nginx/nginx.conf \
43
+ --error-log-path=/var/log/nginx/error.log \
44
+ --http-log-path=/var/log/nginx/access.log \
45
+ --pid-path=/var/run/nginx.pid \
46
+ --lock-path=/var/run/nginx.lock \
47
+ --http-client-body-temp-path=/var/cache/nginx/client_temp \
48
+ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
49
+ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
50
+ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
51
+ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
52
+ --user=nginx \
53
+ --group=nginx \
54
+ --with-http_ssl_module \
55
+ --with-http_realip_module \
56
+ --with-http_addition_module \
57
+ --with-http_sub_module \
58
+ --with-http_dav_module \
59
+ --with-http_flv_module \
60
+ --with-http_mp4_module \
61
+ --with-http_gunzip_module \
62
+ --with-http_gzip_static_module \
63
+ --with-http_random_index_module \
64
+ --with-http_secure_link_module \
65
+ --with-http_stub_status_module \
66
+ --with-http_auth_request_module \
67
+ --with-http_xslt_module=dynamic \
68
+ --with-http_image_filter_module=dynamic \
69
+ --with-http_geoip_module=dynamic \
70
+ --with-threads \
71
+ --with-stream \
72
+ --with-stream_ssl_module \
73
+ --with-stream_ssl_preread_module \
74
+ --with-stream_realip_module \
75
+ --with-stream_geoip_module=dynamic \
76
+ --with-http_slice_module \
77
+ --with-file-aio \
78
+ --with-http_v2_module && \
79
+ make && \
80
+ make install && \
81
+ # 清理编译文件
82
+ cd / && \
83
+ rm -rf /tmp/nginx-${NGINX_VERSION}* && \
84
+ # 创建必要的目录
85
+ mkdir -p /var/cache/nginx && \
86
+ mkdir -p /var/log/nginx && \
87
+ # 设置权限
88
+ chown -R nginx:nginx /var/cache/nginx && \
89
+ chown -R nginx:nginx /var/log/nginx
90
+
91
+ # 创建nginx配置文件
92
+ RUN echo 'user nginx;' > /etc/nginx/nginx.conf && \
93
+ echo 'worker_processes auto;' >> /etc/nginx/nginx.conf && \
94
+ echo 'error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
95
+ echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \
96
+ echo '' >> /etc/nginx/nginx.conf && \
97
+ echo 'events {' >> /etc/nginx/nginx.conf && \
98
+ echo ' worker_connections 1024;' >> /etc/nginx/nginx.conf && \
99
+ echo '}' >> /etc/nginx/nginx.conf && \
100
+ echo '' >> /etc/nginx/nginx.conf && \
101
+ echo 'http {' >> /etc/nginx/nginx.conf && \
102
+ echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf && \
103
+ echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf && \
104
+ echo ' sendfile on;' >> /etc/nginx/nginx.conf && \
105
+ echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \
106
+ echo '' >> /etc/nginx/nginx.conf && \
107
+ echo ' server {' >> /etc/nginx/nginx.conf && \
108
+ echo ' listen 80;' >> /etc/nginx/nginx.conf && \
109
+ echo ' server_name localhost;' >> /etc/nginx/nginx.conf && \
110
+ echo ' location / {' >> /etc/nginx/nginx.conf && \
111
+ echo ' root /usr/share/nginx/html;' >> /etc/nginx/nginx.conf && \
112
+ echo ' index index.html index.htm;' >> /etc/nginx/nginx.conf && \
113
+ echo ' }' >> /etc/nginx/nginx.conf && \
114
+ echo ' }' >> /etc/nginx/nginx.conf && \
115
+ echo '}' >> /etc/nginx/nginx.conf
116
+
117
+ # 创建默认网页目录和文件
118
+ RUN mkdir -p /usr/share/nginx/html && \
119
+ echo '<h1>Welcome to nginx!</h1>' > /usr/share/nginx/html/index.html && \
120
+ echo '<p>Java Version:</p>' >> /usr/share/nginx/html/index.html && \
121
+ java -version 2>&1 | head -1 | sed 's/^/<p>/' | sed 's/$/<\/p>/' >> /usr/share/nginx/html/index.html
122
+
123
+ # 验证安装
124
+ RUN nginx -t && \
125
+ java -version
126
+
127
+ # 暴露端口
128
+ # EXPOSE 80 443
129
+ EXPOSE 80
130
+
131
+ # 创建启动脚本
132
+ RUN echo '#!/bin/sh' > /start.sh && \
133
+ echo 'echo "Starting services..."' >> /start.sh && \
134
+ echo 'echo "Java version:"' >> /start.sh && \
135
+ echo 'java -version' >> /start.sh && \
136
+ echo 'echo "Nginx version:"' >> /start.sh && \
137
+ echo 'nginx -v' >> /start.sh && \
138
+ echo 'echo "Starting nginx..."' >> /start.sh && \
139
+ echo 'nginx -g "daemon off;"' >> /start.sh && \
140
+ chmod +x /start.sh
141
+
142
+ # 设置工作目录
143
+ WORKDIR /usr/share/nginx/html
144
+
145
+ # 启动命令
146
+ CMD ["/start.sh"]