npx skills add https://github.com/alfredang/skills --skill 'Docker Hub'构建 Docker 镜像并推送到 Docker Hub 上的 tertiaryinfotech。如果项目不存在 Dockerfile,则通过检测项目类型自动生成一个。
/docker-hub 或 docker-hub
Docker 与部署
docker hub, docker push, docker build, docker image, dockerfile, container, containerize, push image, docker deploy, docker hub push, tertiaryinfotech, build image, docker registry
构建 Docker 镜像并将其推送到 Docker Hub 上 tertiaryinfotech 组织下。自动检测项目类型,如果缺少 Dockerfile 则生成一个,构建镜像,并将其推送到 https://hub.docker.com/repositories/tertiaryinfotech。
此技能使用 Claude Code 订阅计划 运行。请勿使用按量付费的 API 密钥。所有 AI 操作都应在具有有效订阅的 Claude Code CLI 环境中执行。
我将帮助您构建 Docker 镜像并将其推送到 Docker Hub!
工作流程包括:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 步骤 | 描述 |
|---|
| 预检 | 验证 Docker CLI、守护进程和 Docker Hub 身份验证 |
| Dockerfile | 检测项目类型,如果缺少则生成 Dockerfile |
| 构建 | 构建标记为 tertiaryinfotech/<project>:latest 的镜像 |
| 推送 | 将镜像推送到 Docker Hub |
| 验证 | 确认推送并打印 Docker Hub URL |
执行 /docker-hub 时,请遵循以下工作流程:
docker --version
如果未安装 Docker,请通知用户并停止。提供安装链接:https://docs.docker.com/get-docker/
docker info > /dev/null 2>&1
如果守护进程未运行,请通知用户:
Docker daemon is not running. Please start Docker Desktop or the Docker service.
docker login --username tertiaryinfotech
如果未登录,提示用户进行身份验证。推送目标始终是 tertiaryinfotech 账户。
PROJECT_NAME=$(basename "$(pwd)")
IMAGE_NAME="tertiaryinfotech/$PROJECT_NAME"
echo "Image will be pushed as: $IMAGE_NAME:latest"
镜像名称始终为 tertiaryinfotech/<文件夹名称>。除非用户另行指定,否则标签默认为 latest。
ls Dockerfile 2>/dev/null
如果 Dockerfile 存在: 跳转到阶段 3。
如果 Dockerfile 不存在: 检测项目类型并生成相应的 Dockerfile。
按顺序检查以下文件以确定项目类型:
| 文件 | 项目类型 |
|---|---|
package.json | Node.js(检查是否为 Next.js、Vite、Express 等) |
requirements.txt | Python (pip) |
pyproject.toml | Python (uv/poetry) |
Pipfile | Python (pipenv) |
go.mod | Go |
pom.xml | Java (Maven) |
build.gradle | Java (Gradle) |
Cargo.toml | Rust |
Gemfile | Ruby |
index.html(无框架文件) | 静态站点 |
根据检测到的项目类型,遵循以下最佳实践生成可用于生产的 Dockerfile:
latest)的官方基础镜像.dockerignore 排除不必要的文件Node.js 示例(Express/通用):
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
FROM node:20-alpine
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder /app .
USER appuser
EXPOSE 3000
CMD ["node", "index.js"]
Node.js 示例(Next.js):
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
USER appuser
EXPOSE 3000
CMD ["npm", "start"]
Python 示例(pip):
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /install /usr/local
COPY . .
USER appuser
EXPOSE 8000
CMD ["python", "main.py"]
Python 示例(uv/pyproject.toml):
FROM python:3.12-slim
WORKDIR /app
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
COPY pyproject.toml uv.lock* ./
RUN uv sync --frozen --no-dev
COPY . .
RUN useradd -r -s /bin/false appuser
USER appuser
EXPOSE 8000
CMD ["uv", "run", "python", "main.py"]
Go 示例:
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main .
FROM alpine:3.19
WORKDIR /app
RUN adduser -D -s /bin/sh appuser
COPY --from=builder /app/main .
USER appuser
EXPOSE 8080
CMD ["./main"]
静态站点示例(nginx):
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Rust 示例:
FROM rust:1.77-slim AS builder
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release
FROM debian:bookworm-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /app/target/release/* .
USER appuser
EXPOSE 8080
CMD ["./app"]
Java (Maven) 示例:
FROM maven:3.9-eclipse-temurin-21 AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -DskipTests
FROM eclipse-temurin:21-jre
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /app/target/*.jar app.jar
USER appuser
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
Ruby 示例:
FROM ruby:3.3-slim AS builder
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install --without development test
FROM ruby:3.3-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY . .
USER appuser
EXPOSE 3000
CMD ["ruby", "app.rb"]
调整生成的 Dockerfile 以匹配特定项目(例如,检查 package.json 中的 start 脚本,检测主入口文件,检查特定于框架的构建命令)。
如果不存在 .dockerignore,则生成一个适合项目类型的:
node_modules
.git
.gitignore
.env
.env.*
*.md
.DS_Store
.vscode
.idea
__pycache__
*.pyc
.pytest_cache
target
dist
build
.next
PROJECT_NAME=$(basename "$(pwd)")
docker build -t tertiaryinfotech/$PROJECT_NAME:latest .
如果构建失败:
PROJECT_NAME=$(basename "$(pwd)")
docker push tertiaryinfotech/$PROJECT_NAME:latest
始终推送到 tertiaryinfotech。 这是硬编码的,不应更改。
如果因身份验证导致推送失败:
docker login --username tertiaryinfotech
然后重试推送。
PROJECT_NAME=$(basename "$(pwd)")
echo "Image pushed successfully!"
echo "Docker Hub: https://hub.docker.com/r/tertiaryinfotech/$PROJECT_NAME"
echo "Pull command: docker pull tertiaryinfotech/$PROJECT_NAME:latest"
.dockerignore 以实现干净的构建tertiaryinfotech 组织构建和标记镜像latest)tertiaryinfotech Docker Hub 账户tertiaryinfotech/<文件夹名称>latest —— 用户可以根据需要指定自定义标签DOCKER_USERNAME 或 DOCKER_PASSWORD 环境变量,可用于非交互式登录每周安装次数
0
仓库
GitHub 星标数
1
首次出现
1970年1月1日
安全审计
Build and push Docker images to tertiaryinfotech on Docker Hub. Auto-generates a Dockerfile if one doesn't exist by detecting the project type.
/docker-hub or docker-hub
Docker & Deployment
docker hub, docker push, docker build, docker image, dockerfile, container, containerize, push image, docker deploy, docker hub push, tertiaryinfotech, build image, docker registry
Build and push Docker images to Docker Hub under the tertiaryinfotech organization. Automatically detects the project type, generates a Dockerfile if missing, builds the image, and pushes it to https://hub.docker.com/repositories/tertiaryinfotech.
This skill runs using Claude Code with subscription plan. Do NOT use pay-as-you-go API keys. All AI operations should be executed through the Claude Code CLI environment with an active subscription.
I'll help you build and push your Docker image to Docker Hub!
The workflow includes:
| Step | Description |
|---|---|
| Pre-flight | Verify Docker CLI, daemon, and Docker Hub authentication |
| Dockerfile | Detect project type and generate Dockerfile if missing |
| Build | Build image tagged as tertiaryinfotech/<project>:latest |
| Push | Push image to Docker Hub |
| Verify | Confirm push and print Docker Hub URL |
When executing /docker-hub, follow this workflow:
docker --version
If Docker is not installed, inform the user and stop. Provide installation link: https://docs.docker.com/get-docker/
docker info > /dev/null 2>&1
If the daemon is not running, inform the user:
Docker daemon is not running. Please start Docker Desktop or the Docker service.
docker login --username tertiaryinfotech
If not logged in, prompt the user to authenticate. The push target is always the tertiaryinfotech account.
PROJECT_NAME=$(basename "$(pwd)")
IMAGE_NAME="tertiaryinfotech/$PROJECT_NAME"
echo "Image will be pushed as: $IMAGE_NAME:latest"
The image name is always tertiaryinfotech/<folder-name>. The tag defaults to latest unless the user specifies otherwise.
ls Dockerfile 2>/dev/null
If Dockerfile exists: Skip to Phase 3.
If Dockerfile does NOT exist: Detect the project type and generate an appropriate Dockerfile.
Check for these files in order to determine the project type:
| File | Project Type |
|---|---|
package.json | Node.js (check for Next.js, Vite, Express, etc.) |
requirements.txt | Python (pip) |
pyproject.toml | Python (uv/poetry) |
Pipfile | Python (pipenv) |
go.mod | Go |
pom.xml | Java (Maven) |
Based on the detected project type, generate a production-ready Dockerfile following these best practices:
latest).dockerignore to exclude unnecessary filesNode.js Example (Express/generic):
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
FROM node:20-alpine
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder /app .
USER appuser
EXPOSE 3000
CMD ["node", "index.js"]
Node.js Example (Next.js):
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
USER appuser
EXPOSE 3000
CMD ["npm", "start"]
Python Example (pip):
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /install /usr/local
COPY . .
USER appuser
EXPOSE 8000
CMD ["python", "main.py"]
Python Example (uv/pyproject.toml):
FROM python:3.12-slim
WORKDIR /app
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
COPY pyproject.toml uv.lock* ./
RUN uv sync --frozen --no-dev
COPY . .
RUN useradd -r -s /bin/false appuser
USER appuser
EXPOSE 8000
CMD ["uv", "run", "python", "main.py"]
Go Example:
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main .
FROM alpine:3.19
WORKDIR /app
RUN adduser -D -s /bin/sh appuser
COPY --from=builder /app/main .
USER appuser
EXPOSE 8080
CMD ["./main"]
Static Site Example (nginx):
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Rust Example:
FROM rust:1.77-slim AS builder
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release
FROM debian:bookworm-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /app/target/release/* .
USER appuser
EXPOSE 8080
CMD ["./app"]
Java (Maven) Example:
FROM maven:3.9-eclipse-temurin-21 AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -DskipTests
FROM eclipse-temurin:21-jre
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /app/target/*.jar app.jar
USER appuser
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
Ruby Example:
FROM ruby:3.3-slim AS builder
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install --without development test
FROM ruby:3.3-slim
WORKDIR /app
RUN useradd -r -s /bin/false appuser
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY . .
USER appuser
EXPOSE 3000
CMD ["ruby", "app.rb"]
Adapt the generated Dockerfile to match the specific project (e.g., check package.json for the start script, detect the main entry file, check for framework-specific build commands).
If no .dockerignore exists, generate one appropriate for the project type:
node_modules
.git
.gitignore
.env
.env.*
*.md
.DS_Store
.vscode
.idea
__pycache__
*.pyc
.pytest_cache
target
dist
build
.next
PROJECT_NAME=$(basename "$(pwd)")
docker build -t tertiaryinfotech/$PROJECT_NAME:latest .
If the build fails:
PROJECT_NAME=$(basename "$(pwd)")
docker push tertiaryinfotech/$PROJECT_NAME:latest
Always push totertiaryinfotech. This is hardcoded and should never be changed.
If push fails due to authentication:
docker login --username tertiaryinfotech
Then retry the push.
PROJECT_NAME=$(basename "$(pwd)")
echo "Image pushed successfully!"
echo "Docker Hub: https://hub.docker.com/r/tertiaryinfotech/$PROJECT_NAME"
echo "Pull command: docker pull tertiaryinfotech/$PROJECT_NAME:latest"
.dockerignore for clean buildstertiaryinfotech organizationlatest)tertiaryinfotech Docker Hub accounttertiaryinfotech/<folder-name>latest — user can specify a custom tag if neededDOCKER_USERNAME or DOCKER_PASSWORD environment variables are set, they can be used for non-interactive loginWeekly Installs
0
Repository
GitHub Stars
1
First Seen
Jan 1, 1970
Security Audits
build.gradle |
| Java (Gradle) |
Cargo.toml | Rust |
Gemfile | Ruby |
index.html (no framework files) | Static site |