Login to GitLab container registry from CI

I’m using GitLab.com and trying to push an image to a different container repository under the same project group (on GitLab.com) and I’m having some issues logging in. I’ve setup the DOCKER_AUTH_CONFIG variable. Here’s my build step:

build:
  stage: build
  services:
    - docker:dind
  script:
    - docker login registry.gitlab.com
    - docker build -t registry.gitlab.com/<group>/<repo>:$CI_BUILD_REF_NAME -f Dockerfile .
    - docker push registry.gitlab.com/<group>/<project>:$CI_BUILD_REF_NAME

This fails like so:

$ docker login registry.gitlab.com
Error: Cannot perform an interactive login from a non TTY device

I’ve no idea why this doesn’t work, as I can echo out the env variable and it does in fact exist. Does anyone have some suggestions for why this is failing?

DOCKER_AUTH_CONFIG is not recognized by the docker command line client. It is recognized by the gitlab runner and is used when the runner tries to satisfy image: or service: requirements.

In your build script you will need to specify the credentials by providing the -u and -p options or writing out to .docker/config.json. See the docker login doc for details on the latter. If the docker login command isn’t given the credentials by either of these means it falls back to interactive prompts for the username and password which is why you are getting the error.

Ahhhh okay this makes sense. Thank you! Thanks for the info!

I ended up re-structuring my project to not have to do this anymore, but this solution does work.