'Docker compose dind deploy to GitLab Registry

I am working on MS Blazor server two projects solution (Core 6) and GitLab.

docker-compose.yml file:

version: '3.4'

services:

  admin:

    image: ${DOCKER_REGISTRY-}admin

    build:

      context: .

      dockerfile: FrontEnd/Admin/Dockerfile

  enrollment:

    image: ${DOCKER_REGISTRY-}enrollment

    build:

      context: .

      dockerfile: FrontEnd/Enrollment/Dockerfile

GitLab pipeline file:

image: docker:stable

services:

  - docker:dind

before_script:

  - docker info

build:  

  only:

    - DockerComposeSupported

  before_script:

    - docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}

  script:

    - apk add --no-cache docker-compose

    - docker-compose build #Works fine

    - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH} # Here is the error

  after_script:

    - docker logout ${CI_REGISTRY}

  stage: build

The problem is in line: - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}, the error is The push refers to repository [registry.gitlab.com/xxx/yyy/zzz] An image does not exist locally with the tag: registry.gitlab.com/xxx/yyy/zzz

I originally grab the code from Gitlab, it was docker build -t registry.gitlab.com/xxx/yyy/zzz . But the docker build is looking for a docker file in the root directory and I do not have one, I have docker-compose only so I need to use the "docker-compose build" but this command does not have any directory parameter. Any help will be greatly appreciated.



Solution 1:[1]

Use a different variable defined by GitLab in CI: CI_REGISTRY_IMAGE="registry.example.com/org/repo"

version: '3.4'
services:
  admin:
    image: ${CI_REGISTRY_IMAGE}-admin
    build:
      context: .
      dockerfile: FrontEnd/Admin/Dockerfile
  enrollment:
    image: ${CI_REGISTRY_IMAGE}-enrollment
    build:
      context: .
      dockerfile: FrontEnd/Enrollment/Dockerfile

docker-compose has a nifty feature where you can set this variable in a .env file within the same directory as the docker-compose.yml file. You will only need this file for local development.

# .env
CI_REGISTRY_IMAGE="registry.example.com/org/repo"

Solution 2:[2]

Thanks, Richard and Danielnelz! I've found a solution for the "requested access to the resource is denied" error. I had "{CI_REGISTRY_IMAGE}-admin" project reference but it should be {CI_REGISTRY_IMAGE}/admin. Now the docker push to the GitLab registry is working fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Richard
Solution 2 kav48382