vue dockerfile
# 首先,构建 Vue 3 应用
FROM node:16.14.2-slim as build-stage
WORKDIR /app
COPY package*.json ./
RUN yarn install
COPY . .
RUN yarn build:prod
# 然后,使用 Nginx 作为 Web 服务器
FROM nginx:latest as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.html$is_args$query_string;
}
}
}
php Dockerfile
# 基于官方 PHP 8.1 镜像
FROM php:8.1-fpm-alpine
# 更新软件包源
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main/" > /etc/apk/repositories; \
echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community/" >> /etc/apk/repositories;
COPY php.ini /usr/local/etc/php/php.ini
# 安装基本的依赖和工具
RUN apk update && \
apk add --no-cache \
nginx\
curl \
git \
unzip \
libzip-dev \
libzip \
oniguruma-dev \
libpng \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
autoconf g++ make \
imagemagick-dev oniguruma-dev gettext-dev icu-dev \
supervisor && \
docker-php-ext-install pdo_mysql zip mbstring opcache bcmath pcntl exif gd gettext intl fileinfo zip \
&& pecl install redis imagick && docker-php-ext-enable redis pdo_mysql zip mbstring opcache bcmath pcntl exif gd gettext intl imagick && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
#RUN chmod 755 -R /usr/local/lib/php/extensions/no-debug-non-zts-20210902/
EXPOSE 80 443 9000
# 复制 Nginx 配置文件到容器中
COPY nginx.conf /etc/nginx/nginx.conf
CMD php-fpm -D && nginx -g "daemon off;"
nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.php index.html index.nginx-debian.html;
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET,POST';
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
php.ini
[PHP]
; PHP引擎设置
engine = On
short_open_tag = On
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
; 序列化精度
serialize_precision = -1
; 禁用的函数
disable_functions = passthru, system, chroot, chgrp, chown, shell_exec, pcntl_exec, ini_alter, ini_restore, dl, openlog, syslog, readlink, popepassthru, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority, imap_open, apache_setenv
; 禁用的类
disable_classes =
; Zend引擎设置
zend.enable_gc = On
zend.exception_ignore_args = On
zend.exception_string_param_max_len = 0
; 显示PHP版本
expose_php = Off
; 最大执行时间和输入时间
max_execution_time = 30000
max_input_time = 6000
; 内存限制
memory_limit = 2048M
; 错误报告级别
error_reporting = E_ALL & ~E_NOTICE
; 显示错误信息
display_errors = On
; 显示启动错误信息
display_startup_errors = Off
; 记录错误信息到日志
log_errors = On
; 是否忽略重复的错误信息
ignore_repeated_errors = Off
; 是否忽略重复的错误来源
ignore_repeated_source = Off
; 报告内存泄漏
report_memleaks = On
; 变量的解析顺序
variables_order = "GPCS"
; 请求的解析顺序
request_order = "GP"
; 注册命令行参数
register_argc_argv = Off
; 自动注册全局变量
auto_globals_jit = On
; POST数据最大尺寸
post_max_size = 200M
; 在每个脚本之前自动包含文件
auto_prepend_file =
; 在每个脚本之后自动包含文件
auto_append_file =
; 默认MIME类型
default_mimetype = "text/html"
; 默认字符集
default_charset = "UTF-8"
; 文档根目录
doc_root =
; 用户目录
user_dir =
; 是否启用动态链接库加载
enable_dl = Off
; 修正PATH_INFO的问题
cgi.fix_pathinfo = 1
; 是否允许文件上传
file_uploads = On
; 文件上传的最大尺寸
upload_max_filesize = 200M
; 单次请求最大文件上传数量
max_file_uploads = 200
; 是否允许打开URL
allow_url_fopen = On
; 是否允许包含URL
allow_url_include = Off
; 默认套接字超时时间
default_socket_timeout = 120
[CLI Server]
; CLI Web服务器是否使用ANSI颜色编码
cli_server.color = On
[Date]
; 默认时区
date.timezone = PRC
[Pdo_mysql]
; PDO MySQL默认套接字
pdo_mysql.default_socket =
[mail function]
; SMTP服务器
SMTP = localhost
; SMTP端口
smtp_port = 25
; 发送邮件的路径
sendmail_path = /usr/sbin/sendmail -t -i
; 是否在邮件头中添加"X-PHP-Originating-Script"信息
mail.add_x_header = Off
[ODBC]
; 是否允许持久化连接
odbc.allow_persistent = On
; 检查持久化连接
odbc.check_persistent = On
; 最大持久化连接数
odbc.max_persistent = -1
; 最大连接数
odbc.max_links = -1
; 默认的行记录长度
odbc.defaultlrl = 4096
; 默认的二进制模式
odbc.defaultbinmode = 1
[MySQLi]
; 最大持久化连接数
mysqli.max_persistent = -1
; 是否允许持久化连接
mysqli.allow_persistent = On
; 最大连接数
mysqli.max_links = -1
; 默认端口号
mysqli.default_port = 3306
; 默认套接字
mysqli.default_socket =
; 默认主机
mysqli.default_host =
; 默认用户名
mysqli.default_user =
; 默认密码
mysqli.default_pw =
; 是否重连
mysqli.reconnect = Off
[mysqlnd]
; 是否收集统计信息
mysqlnd.collect_statistics = On
; 是否收集内存统计信息
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
; 是否允许持久化连接
pgsql.allow_persistent = On
; 是否自动重置持久化连接
pgsql.auto_reset_persistent = Off
; 最大持久化连接数
pgsql.max_persistent = -1
; 最大连接数
pgsql.max_links = -1
; 是否忽略通知信息
pgsql.ignore_notice = 0
; 是否记录通知信息
pgsql.log_notice = 0
[bcmath]
; 小数计算精度
bcmath.scale = 0
[Session]
; 会话保存处理程序
session.save_handler = files
; 使用严格模式
session.use_strict_mode = 0
; 是否使用会话Cookie
session.use_cookies = 1
; 是否只使用会话Cookie
session.use_only_cookies = 1
; 会话名称
session.name = PHPSESSID
; 自动启动会话
session.auto_start = 0
; 会话Cookie的生命周期
session.cookie_lifetime = 0
; 会话Cookie路径
session.cookie_path = /
; 会话Cookie域
session.cookie_domain =
; 是否将会话Cookie标记为HTTP Only
session.cookie_httponly =
; 会话Cookie SameSite属性
session.cookie_samesite =
; 序列化处理程序
session.serialize_handler = php
; 垃圾回收概率
session.gc_probability = 1
; 垃圾回收分母
session.gc_divisor = 1000
; 会话的最大生命周期
session.gc_maxlifetime = 1440
; 引用检查
session.referer_check =
; 缓存限制器
session.cache_limiter = nocache
; 缓存过期时间
session.cache_expire = 180
; 是否启用透明会话ID
session.use_trans_sid = 0
; 会话ID长度
session.sid_length = 26
; 会话ID的有效字符集
session.sid_bits_per_character = 5
[Assertion]
; 断言级别
zend.assertions = -1
[Tidy]
; 是否清理输出
tidy.clean_output = Off
[soap]
; 是否启用SOAP WSDL缓存
soap.wsdl_cache_enabled = 1
; SOAP WSDL缓存目录
soap.wsdl_cache_dir = "/tmp"
; SOAP WSDL缓存生命周期
soap.wsdl_cache_ttl = 86400
; SOAP WSDL缓存数量限制
soap.wsdl_cache_limit = 5
[ldap]
; 最大连接数
ldap.max_links = -1
[curl]
; CURL CA证书路径
;curl.cainfo = /etc/pki/tls/certs/ca-bundle.crt
[openssl]
; OpenSSL CA证书路径
;openssl.cafile = /etc/pki/tls/certs/ca-bundle.crt
[opcache]
;zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20210902/opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0
opcache.revalidate_freq=0
opcache.fast_shutdown=1
opcache.enable_cli=1
; Example bcmath configuration
[bcmath]
bcmath.scale = 0
; Example pcntl configuration
[pcntl]
pcntl.enable=1
; Example gd configuration
[gd]
gd.enable=1
; Example gettext configuration
[gettext]
gettext.enable=1
; Example intl configuration
[intl]
intl.default_locale = "en"
intl.error_level = E_WARNING
; Example fileinfo configuration
[fileinfo]
fileinfo.enable=1
复用基础镜像
# 基于官方 PHP 8.1 镜像
FROM registry.cn-guangzhou.aliyuncs.com/yansoa/php-alpine:8.1.21
#FROM yileo-alpine:1.0
COPY . /var/www/html/
COPY ./.env /var/www/html/
WORKDIR /var/www/html
RUN yes | composer update --no-dev && \
chmod -R 755 .. && \
chown -R www-data:www-data .. && \
chown -R www-data:www-data /var/www/html/storage/framework/ && \
php artisan optimize
go dockerfile
# 使用官方的 Golang 镜像作为基础镜像
FROM golang:1.21-alpine
# 设置容器内的当前工作目录
WORKDIR /app
# 复制 go mod 和 sum 文件
COPY go.mod go.sum ./
# 下载所有依赖项。如果 go.mod 和 go.sum 文件没有改变,依赖项会被缓存
RUN go mod download
# 将当前目录的源代码复制到工作目录
COPY . .
# 构建 Go 应用程序
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o agent-go-amd64 -trimpath -ldflags "-s -w" .
EXPOSE 9091
# 设置运行可执行文件的命令
CMD ["./agent-go-amd64"]