docker 常用基础镜像打包

JAVA

Dockerfile

# 8的镜像比较小,但是在某些机器运行可能会有问题
#FROM openjdk:8-jdk-alpine
# ARM机器推荐
# FROM arm64v8/openjdk:17-jdk
FROM openjdk:17-jdk-alpine
ENV LANG en_US.UTF-8
RUN echo "http://mirrors.huaweicloud.com/alpine/v3.6/main" > /etc/apk/repositories \
    && echo "http://mirrors.huaweicloud.com/alpine/v3.6/community" >> /etc/apk/repositories \
    && apk update upgrade \
    && apk add --no-cache procps unzip curl bash tzdata \
    && apk add ttf-dejavu \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone
# 将window字体全部转移 会导致镜像很大 C:\Windows\Fonts 一般富文本转word需要
#ADD Fonts /usr/share/fonts
# 只导入一个字体微软雅黑 可以应对一般的excel导入导出
ADD msyh.ttf /usr/share/fonts/msyh.ttf

node

default.conf

server {
    listen       80;
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    server_name  localhost;
    client_max_body_size 200m;
    proxy_connect_timeout 5m;
    proxy_send_timeout 5m;     # 设置发送超时时间,
    proxy_read_timeout 5m;	   # 设置读取超时时间。
    keepalive_timeout 5m;
    location / {
        add_header Cache-Control "no-cache";
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }

    location /f/ {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://test-server;
    }

    location /prod-api/{
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://test-server/;
        proxy_read_timeout 5m;      # 设置从上游服务器读取响应的超时时间为5分钟
        client_body_timeout 5m;     # 设置接收客户端请求正文的超时时间为5分钟
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Dockerfile

# ARM机器推荐
#FROM arm64v8/nginx:1.24.0
FROM nginx:1.24.0
RUN rm /etc/nginx/conf.d/default.conf
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ADD default.conf /etc/nginx/conf.d/
COPY dist/ /usr/share/nginx/html/
EXPOSE 80

mysql

utf8mb4.cnf 注意必须chmod 444 utf8mb4.cnf 设置只读 否则无法启动

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
symbolic-links=0

log-bin=/var/lib/mysql/mysql-bin
server-id=1
binlog_format=MIXED
expire_logs_days=30
# 表名忽略大小写
lower_case_table_names=1
# 最大连接数
max-connections=2000
# 时区
default-time_zone = '+8:00'

Dockerfile

FROM arm64v8/mysql:8.0.31
COPY utf8mb4.cnf /etc/mysql/conf.d/utf8mb4.cnf
COPY ./sql  /tmp/sql
RUN mv /tmp/sql/*.sql /docker-entrypoint-initdb.d
RUN rm -rf /tmp/sql

init.sql

-- 注意加建库语句
CREATE DATABASE IF NOT EXISTS `test` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE `test`;
posted @ 2023-12-20 11:31  Ranger-dev  阅读(98)  评论(0编辑  收藏  举报