您当前的位置:首页 > 学海无涯 > 其他网站首页其他
常用基础环境Dockerfile
发布时间:2021-01-23作者:♂逸風★淩軒
Nginx:
FROM nginx RUN rm /etc/nginx/nginx.conf ADD nginx.conf /etc/nginx/ COPY dist /usr/share/nginx/html/
nginx.conf
worker_processes auto;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
##set user real ip to remote addr 二层Nginx代理
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
##set user real ip to remote addr三层Nginx代理
#set_real_ip_from 后面是可信 IP 规则
set_real_ip_from 10.10.1.0/24;
set_real_ip_from 192.168.199.0/24;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
server_tokens off;
#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
log_format eslog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log off;
log_format nomal [$time_local] - $remote_addr - $request_method - $scheme - $server_protocol - $status - $http_host - [$http_referer] - [$http_user_agent]- $remote_user;
server{
listen 80 default;
server_name localhost;
location / {
try_files $uri $uri/ @router;
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location @router {
rewrite ^.*$ /index.html last;
}
}
}.Net 3.1
全功能SDK
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base WORKDIR /app COPY publish ./ FROM base AS final WORKDIR /app RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENTRYPOINT ["dotnet", "host.dll"]
API接口类
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base WORKDIR /app COPY publish ./ FROM base AS final WORKDIR /app RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENTRYPOINT ["dotnet", "api.dll"]
Host类
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS base WORKDIR /app COPY publish ./ FROM base AS final WORKDIR /app RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENTRYPOINT ["dotnet", "host.dll"]
.Net 5.0
镜像由.Net 3.1变更为以下
mcr.microsoft.com/dotnet/runtime:5.0 mcr.microsoft.com/dotnet/sdk:5.0 mcr.microsoft.com/dotnet/aspnet:5.0
Java
FROM rockylinux:9 WORKDIR /app COPY jdk-21_linux-x64_bin.rpm ./ RUN rpm -ivh jdk-21_linux-x64_bin.rpm && rm -rf jdk-21_linux-x64_bin.rpm RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=http://mirrors.aliyun.com/rockylinux|g' -i.bak /etc/yum.repos.d/rocky*.repo RUN yum clean all -y && yum makecache -y && yum install -y gcc gd gd-devel freetype* RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
使用官方镜像,镜像较小,但不能保证jdk与开发使用一致,openjdk与jdk部分可能存在差距
# 使用官方OpenJDK运行时作为基础镜像 FROM openjdk:11-jre-slim # 设置工作目录 WORKDIR /app # 设置时区 ENV TZ=Asia/Shanghai # 复制jar文件到容器中 COPY *.jar app.jar # 暴露端口 EXPOSE 8080 # 启动Java应用程序 ENTRYPOINT ["java", "-jar", "app.jar"]
Python
FROM python:3.6 ENV TZ Asia/Shanghai WORKDIR /app COPY requirements.txt /app RUN pip install -r /app/requirements.txt COPY finovy /app EXPOSE 5000 CMD ["python", "/app/run.py" ]
# Backend Dockerfile - Flask app served by Gunicorn
FROM harbor.apps.kube-k8s.52aiops.cn/library/python:3.11-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple \
PIP_TRUSTED_HOST=mirrors.aliyun.com
WORKDIR /app
# System deps (build essentials for some packages)
# Robustly switch Debian sources to Aliyun and install deps
RUN set -eux; \
# Some slim images use /etc/apt/sources.list.d/debian.sources only; remove to avoid mismatch
if [ -f /etc/apt/sources.list.d/debian.sources ]; then rm -f /etc/apt/sources.list.d/debian.sources; fi; \
# Generate a fresh sources.list from the distro codename
. /etc/os-release; \
echo "deb http://mirrors.aliyun.com/debian ${VERSION_CODENAME} main contrib non-free" > /etc/apt/sources.list; \
echo "deb http://mirrors.aliyun.com/debian ${VERSION_CODENAME}-updates main contrib non-free" >> /etc/apt/sources.list; \
echo "deb http://mirrors.aliyun.com/debian-security ${VERSION_CODENAME}-security main contrib non-free" >> /etc/apt/sources.list; \
apt-get -o Acquire::Retries=3 update; \
apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
pkg-config; \
rm -rf /var/lib/apt/lists/*
# Install dependencies first
COPY requirements.txt /app/requirements.txt
RUN python -m pip install --upgrade pip \
&& pip install -r requirements.txt
# Copy app code
COPY . /app
# Expose port
EXPOSE 5000
# Use Gunicorn to serve the Flask app
# Expect a wsgi.py exposing `app`
CMD ["gunicorn", "wsgi:app", "--bind", "0.0.0.0:5000", "--workers", "2", "--threads", "4", "--timeout", "60"]NodeJS
## Multi-stage build: build with Node, serve with Nginx # 1) Build stage FROM node:20-alpine AS build WORKDIR /app COPY package*.json /app/ # Use China npm mirror for faster install RUN npm config set registry https://registry.npmmirror.com \ && (npm ci || npm i) COPY . /app RUN npm run build # 2) Runtime stage FROM nginx:1.25-alpine AS runtime COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
关键字词:Dockerfile

下一篇:Vue项目使用二级目录
相关文章
-
无相关信息