Create docker-build.yml #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- main # 你可以根据需要更改触发条件,如 `main` 分支 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. 检出代码 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# 2. 设置 Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# 3. 登录 Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/#-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} # 你的 Docker Hub 用户名 | |
password: ${{ secrets.DOCKER_PASSWORD }} # 你的 Docker Hub 密码 (存储在 GitHub Secrets) | |
# 4. 构建 Docker 镜像 | |
- name: Build Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/your-image-name:latest . | |
# 5. 推送 Docker 镜像到 Docker Hub | |
- name: Push Docker image | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/your-image-name:latest |