docker-setup

Docker 容器化配置指南

⭐182stars🔀32forks📁View on GitHub🕐Updated Jan 1, 2026⬇️1downloads

When & Why to Use This Skill

This Claude skill provides a comprehensive guide for Docker containerization, focusing on industry best practices for creating efficient Dockerfiles and managing multi-container environments. It features optimized multi-stage builds for Java Spring Boot applications and ready-to-use Docker Compose configurations to streamline the transition from development to production with consistent infrastructure as code.

Use Cases

  • Microservices Containerization: Implementing multi-stage Docker builds to create lightweight, production-ready images for Java and Spring Boot applications.
  • Development Environment Standardization: Using Docker Compose to orchestrate application services and database dependencies (like MySQL) to ensure 'works on my machine' consistency across teams.
  • CI/CD Pipeline Integration: Leveraging standardized Docker scripts and triggers to automate the building, testing, and deployment phases of the software development lifecycle.
  • Infrastructure Troubleshooting: Providing a quick-access reference for essential Docker CLI commands to manage container lifecycles, inspect logs, and debug runtime environments.
namedocker-setup
descriptionDocker 容器化配置指南
version1.0.0
categorydevops
scriptPathdocker-check.sh
scriptTypebash
autoExecutetrue
scriptTimeout10

Docker 容器化技能包

Dockerfile 最佳实践

Java Spring Boot 应用

# 多阶段构建
FROM maven:3.8-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn clean package -DskipTests

FROM openjdk:17-jdk-slim
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

Docker Compose

version: '3.8'
services:
  app:
    build: .
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=prod
    depends_on:
      - mysql
  
  mysql:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=password
    volumes:
      - mysql_data:/var/lib/mysql

volumes:
  mysql_data:

常用命令

# 构建镜像
docker build -t myapp:latest .

# 运行容器
docker run -d -p 8080:8080 myapp:latest

# 查看日志
docker logs -f container_id

# 进入容器
docker exec -it container_id /bin/bash