Push docker image to GitLab registry from GitLab CI

registry
docker

#1

Hello,
this is my .gitlab-ci.yml file:

stages:
- build
- deploy

build:
  stage: build
  when: on_success
  only:
    - master
  image: docker:stable
  services:
    - docker:dind
  script:
    - docker login registry.gitlab.com
    - docker build -t registry.gitlab.com/hytta-iot/hytta.io .
    - docker push registry.gitlab.com/hytta-iot/hytta.io

I do not understand how I can login to registry.gitlab.com. Since I need to pass username and password, but I cannot just commit them, how would you do it? I am surprised I cannot find one single guide that explains this directly.

Thank you


#2

Hi @lucavallin.
Any success with this? I am trying to achieve exactly the same on our setup


#3

Instructions are here: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#authenticating-to-the-container-registry

The above example would become:

stages:
- build
- deploy

build:
  stage: build
  when: on_success
  only:
    - master
  image: docker:stable
  services:
    - docker:dind
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker build -t $CI_REGISTRY/hytta-iot/hytta.io .
    - docker push $CI_REGISTRY/hytta-iot/hytta.io