Gitlab提供了一個.gitlab-ci.yml
模板,用於構建和發佈圖像到自己的註冊表(點擊項目中的「新文件」,選擇.gitlab-ci.yml
和docker
)。該文件看起來像這樣,它開箱即用:)如何從gitlab-ci發佈碼頭圖像到碼頭集線器
# This file is a template, and might need editing before it works on your project.
# Official docker image.
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
build-master:
stage: build
script:
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
only:
- master
build:
stage: build
script:
- docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
except:
- master
但默認情況下,這將發佈到gitlab的註冊表。我們如何才能發佈到docker hub而不是?