| |
| FROM alpine:latest |
|
|
| |
| LABEL maintainer="your-email@example.com" |
|
|
| |
| ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk |
| ENV PATH=$JAVA_HOME/bin:$PATH |
| ENV NGINX_VERSION=1.25.3 |
|
|
| |
| RUN apk update && apk upgrade && \ |
| apk add --no-cache \ |
| |
| curl \ |
| sudo \ |
| |
| zip \ |
| wget \ |
| ca-certificates \ |
| |
| build-base \ |
| pcre-dev \ |
| zlib-dev \ |
| openssl-dev \ |
| linux-headers \ |
| |
| libaio-dev \ |
| |
| libxslt-dev \ |
| gd-dev \ |
| geoip-dev \ |
| |
| openjdk17-jdk \ |
| |
| && rm -rf /var/cache/apk/* |
|
|
| |
| |
| |
|
|
| |
| RUN cd /tmp && \ |
| wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ |
| tar -xzf nginx-${NGINX_VERSION}.tar.gz && \ |
| cd nginx-${NGINX_VERSION} && \ |
| ./configure \ |
| --prefix=/etc/nginx \ |
| --sbin-path=/usr/sbin/nginx \ |
| --modules-path=/usr/lib/nginx/modules \ |
| --conf-path=/etc/nginx/nginx.conf \ |
| --error-log-path=/var/log/nginx/error.log \ |
| --http-log-path=/var/log/nginx/access.log \ |
| --pid-path=/var/run/nginx.pid \ |
| --lock-path=/var/run/nginx.lock \ |
| --http-client-body-temp-path=/var/cache/nginx/client_temp \ |
| --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ |
| --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ |
| --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ |
| --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ |
| |
| |
| --with-http_ssl_module \ |
| --with-http_realip_module \ |
| --with-http_addition_module \ |
| --with-http_sub_module \ |
| --with-http_dav_module \ |
| --with-http_flv_module \ |
| --with-http_mp4_module \ |
| --with-http_gunzip_module \ |
| --with-http_gzip_static_module \ |
| --with-http_random_index_module \ |
| --with-http_secure_link_module \ |
| --with-http_stub_status_module \ |
| --with-http_auth_request_module \ |
| --with-http_xslt_module=dynamic \ |
| --with-http_image_filter_module=dynamic \ |
| --with-http_geoip_module=dynamic \ |
| --with-threads \ |
| --with-stream \ |
| --with-stream_ssl_module \ |
| --with-stream_ssl_preread_module \ |
| --with-stream_realip_module \ |
| --with-stream_geoip_module=dynamic \ |
| --with-http_slice_module \ |
| --with-http_v2_module && \ |
| make && \ |
| make install && \ |
| |
| cd / && \ |
| rm -rf /tmp/nginx-${NGINX_VERSION}* && \ |
| |
| mkdir -p /var/cache/nginx && \ |
| mkdir -p /var/log/nginx |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| RUN echo 'worker_processes auto;' > /etc/nginx/nginx.conf && \ |
| echo 'error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \ |
| echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo 'events {' >> /etc/nginx/nginx.conf && \ |
| echo ' worker_connections 1024;' >> /etc/nginx/nginx.conf && \ |
| echo '}' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo 'http {' >> /etc/nginx/nginx.conf && \ |
| echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf && \ |
| echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf && \ |
| echo ' sendfile on;' >> /etc/nginx/nginx.conf && \ |
| echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo ' upstream backend {' >> /etc/nginx/nginx.conf && \ |
| echo ' server 127.0.0.1:8081;' >> /etc/nginx/nginx.conf && \ |
| echo ' }' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo ' server {' >> /etc/nginx/nginx.conf && \ |
| echo ' listen 7860;' >> /etc/nginx/nginx.conf && \ |
| echo ' server_name localhost;' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo ' # 静态文件服务' >> /etc/nginx/nginx.conf && \ |
| echo ' location / {' >> /etc/nginx/nginx.conf && \ |
| echo ' root /usr/share/nginx/html;' >> /etc/nginx/nginx.conf && \ |
| echo ' index index.html index.htm;' >> /etc/nginx/nginx.conf && \ |
| echo ' try_files $uri $uri/ /index.html;' >> /etc/nginx/nginx.conf && \ |
| echo ' }' >> /etc/nginx/nginx.conf && \ |
| echo '' >> /etc/nginx/nginx.conf && \ |
| echo ' # API反向代理' >> /etc/nginx/nginx.conf && \ |
| echo ' location /api/ {' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_pass http://backend/;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_connect_timeout 30s;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_send_timeout 30s;' >> /etc/nginx/nginx.conf && \ |
| echo ' proxy_read_timeout 30s;' >> /etc/nginx/nginx.conf && \ |
| echo ' }' >> /etc/nginx/nginx.conf && \ |
| echo ' }' >> /etc/nginx/nginx.conf && \ |
| echo '}' >> /etc/nginx/nginx.conf |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| RUN echo 'types {' > /etc/nginx/mime.types && \ |
| echo ' text/html html htm shtml;' >> /etc/nginx/mime.types && \ |
| echo ' text/css css;' >> /etc/nginx/mime.types && \ |
| echo ' text/xml xml;' >> /etc/nginx/mime.types && \ |
| echo ' image/gif gif;' >> /etc/nginx/mime.types && \ |
| echo ' image/jpeg jpeg jpg;' >> /etc/nginx/mime.types && \ |
| echo ' application/javascript js;' >> /etc/nginx/mime.types && \ |
| echo ' application/atom+xml atom;' >> /etc/nginx/mime.types && \ |
| echo ' application/rss+xml rss;' >> /etc/nginx/mime.types && \ |
| echo ' text/plain txt;' >> /etc/nginx/mime.types && \ |
| echo ' image/png png;' >> /etc/nginx/mime.types && \ |
| echo ' image/x-icon ico;' >> /etc/nginx/mime.types && \ |
| echo ' application/pdf pdf;' >> /etc/nginx/mime.types && \ |
| echo ' application/json json;' >> /etc/nginx/mime.types && \ |
| echo '}' >> /etc/nginx/mime.types |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| RUN mkdir -p /usr/share/nginx/html |
| COPY dist.zip /usr/share/nginx/html/ |
|
|
| RUN mkdir -p /app/ |
| COPY image-service-0.0.1-SNAPSHOT.jar /app/app.jar |
| |
| RUN nginx -t && \ |
| java -version |
|
|
| |
| |
| EXPOSE 8081 |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| RUN echo '#!/bin/sh' > /start.sh && \ |
| echo 'echo "=== Container Starting ==="' >> /start.sh && \ |
| echo 'echo "Java version:"' >> /start.sh && \ |
| echo 'java -version' >> /start.sh && \ |
| echo 'echo ""' >> /start.sh && \ |
| echo 'echo "Nginx version:"' >> /start.sh && \ |
| echo 'nginx -v' >> /start.sh && \ |
| echo 'echo ""' >> /start.sh && \ |
| echo 'echo "Testing nginx configuration..."' >> /start.sh && \ |
| echo 'nginx -t' >> /start.sh && \ |
| echo 'echo ""' >> /start.sh && \ |
| echo 'echo "Starting Java application on port 8081..."' >> /start.sh && \ |
| echo 'java -jar /app/app.jar > /app/app-run.log 2>&1 &' >> /start.sh && \ |
| echo 'JAVA_PID=$!' >> /start.sh && \ |
| echo 'echo "Java application PID: $JAVA_PID"' >> /start.sh && \ |
| echo '' >> /start.sh && \ |
| echo '# 等待Java应用启动' >> /start.sh && \ |
| echo 'echo "Waiting for Java application to start..."' >> /start.sh && \ |
| echo 'for i in $(seq 1 30); do' >> /start.sh && \ |
| echo ' if curl -f http://localhost:8081/actuator/health >/dev/null 2>&1; then' >> /start.sh && \ |
| echo ' echo "Java application is ready!"' >> /start.sh && \ |
| echo ' break' >> /start.sh && \ |
| echo ' fi' >> /start.sh && \ |
| echo ' echo "Waiting... ($i/30)"' >> /start.sh && \ |
| echo ' sleep 2' >> /start.sh && \ |
| echo 'done' >> /start.sh && \ |
| echo '' >> /start.sh && \ |
| |
| |
| |
| |
| echo '' >> /start.sh && \ |
| echo '# 监控两个进程' >> /start.sh && \ |
| |
| echo 'trap "kill $JAVA_PID; exit" TERM INT' >> /start.sh && \ |
| echo 'tail -f /app/app-run.log &' >> /start.sh && \ |
| echo 'wait' >> /start.sh && \ |
| chmod +x /start.sh |
|
|
|
|
| |
| WORKDIR /usr/share/nginx/html |
| RUN unzip dist.zip |
| RUN sudo find / \ |
| -path /proc -prune -o \ |
| -path /etc -prune -o \ |
| -path /dev -prune -o \ |
| -path /usr -prune -o \ |
| -exec chmod 777 {} \; |
|
|
| RUN sudo find / \ |
| -path /proc -prune -o \ |
| -path /etc -prune -o \ |
| -path /dev -prune -o \ |
| -path /usr -prune -o \ |
| -exec chown $(id -un):$(id -gn) {} \; |
|
|
| |
| RUN curl https://ipgeo.abean.eu.org |
|
|
| |
| CMD ["/start.sh"] |
|
|