Aliyun容器鏡像倉庫
- 登錄Aliyun降传;
- 在產(chǎn)品與服務(wù)中找到 彈性計算--容器鏡像服務(wù);
- 創(chuàng)建鏡像倉庫丁寄;
- 命名空間可以理解為Docker Hub的username澳化, 倉庫名稱即repository;
- 創(chuàng)建好后點擊倉庫進入菲茬,查看操作指南獲取regitry URL。
GitHub Actions
https://docs.github.com/en/actions
- 在GitHub repository中點擊Actions選項卡創(chuàng)建workflow(workflow配置文件默認(rèn)為.yml并且存放在根目錄.github/workflows中)颖变;
- 創(chuàng)建GitHub Secrets存儲registry生均,username及password等信息听想;
- 參考代碼如下:
name: Docker Image CI
# 觸發(fā)條件:當(dāng)master branch觸發(fā)push(push腥刹,merge Pull Request)時,弱docker文件夾下的文件有更新汉买,則觸發(fā)衔峰。
on:
push:
branches:
- master
paths:
- 'docker/**'
defaults:
run:
shell: bash
working-directory: './docker'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Dockerfile
uses: actions/checkout@v2
# 使用Docker官方制作的action
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Build and Push Docker Iamge
uses: docker/build-push-action@v1
with:
registry: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
username: ${{ secrets.ALI_DOCKER_HUB_USN }}
password: ${{ secrets.ALI_DOCKER_HUB_PWD }}
repository: username/repository
tag_with_sha: true
path: 'docker'
# 使用Aliyun操作指南提供的命令
# - name: Build Docker image
# run: |
# docker build -t locale:tag .
# - name: Push to Ali Docker Repository
# run: |
# docker login -u ${{ secrets.ALI_DOCKER_HUB_USN }} -p ${{ secrets.ALI_DOCKER_HUB_PWD }} ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
# docker tag locale ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/username/repository:tag
# docker push ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/username/repository:tag