mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-29 13:15:24 +00:00
chore: update content and add generated PDF
This commit is contained in:
@@ -305,7 +305,7 @@ journalctl -u docker -n 100 | grep -i "oom"
|
||||
|
||||
```python
|
||||
# Dockerfile
|
||||
FROM python:3.11-slim
|
||||
FROM python:3.14-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt memory_profiler tracemalloc
|
||||
@@ -424,7 +424,7 @@ chmod +x hadolint
|
||||
|
||||
```dockerfile
|
||||
# Stage 1: 构建阶段
|
||||
FROM golang:1.20-alpine AS builder
|
||||
FROM golang:1.26-alpine AS builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
@@ -453,13 +453,13 @@ COPY --from=builder /build/app /app
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/app"]
|
||||
|
||||
# 最终镜像大小通常 < 15MB(相比 golang:1.20-alpine 的 ~1GB)
|
||||
# 最终镜像大小通常 < 15MB(相比 golang:1.26-alpine 的 ~1GB)
|
||||
```
|
||||
**Node.js 应用的多阶段构建:**
|
||||
|
||||
```dockerfile
|
||||
# Stage 1: 依赖安装
|
||||
FROM node:18-alpine AS dependencies
|
||||
FROM node:24-alpine AS dependencies
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
@@ -467,7 +467,7 @@ RUN npm ci --only=production && \
|
||||
npm cache clean --force
|
||||
|
||||
# Stage 2: 构建阶段
|
||||
FROM node:18-alpine AS builder
|
||||
FROM node:24-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
@@ -477,7 +477,7 @@ COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 3: 运行阶段
|
||||
FROM node:18-alpine
|
||||
FROM node:24-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -504,7 +504,7 @@ CMD ["node", "dist/index.js"]
|
||||
|
||||
```dockerfile
|
||||
# Stage 1: 构建阶段
|
||||
FROM python:3.11-slim AS builder
|
||||
FROM python:3.14-slim AS builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
@@ -516,7 +516,7 @@ COPY requirements.txt .
|
||||
RUN pip install --user --no-cache-dir -r requirements.txt
|
||||
|
||||
# Stage 2: 运行阶段
|
||||
FROM python:3.11-slim
|
||||
FROM python:3.14-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -550,7 +550,7 @@ CMD ["python", "app.py"]
|
||||
□ 使用 BuildKit 缓存优化加速构建
|
||||
|
||||
# 优化示例:
|
||||
FROM ubuntu:22.04
|
||||
FROM ubuntu:24.04
|
||||
|
||||
# ❌ 不推荐
|
||||
RUN apt-get update
|
||||
|
||||
Reference in New Issue
Block a user