I've been trying to pull in a private (custom) MySQL image from my Docker Hub repository to the gitlab-ci.yml pipeline as a service. I have added a before_script that tries to log in to dockerhub with my username and password (CI variables). There's no output in the failed build log suggesting whether the login to Docker Hub was successful or otherwise but I'm assuming not because the pulling of my image fails with the following message (edit: or it's never even attempted because gitlab tries to get the services before it runs the before script?):
repository does not exist or may require 'docker login' (executor_docker.go:168:0s)
I am using a shared runner (because I believe that's my only option using gitlab.com?) I've seen quite a few mentions of the gitlab ci token for docker but I've found no documentation explaining how to facilitate this.
I'm sure I'm just overlooking something/not understanding or coming across the appropriate solution in my searches so apologies if I'm just being inexperienced and thanks in advance for any help.
My gitlab-ci (the maven variables are because this project's build has a dependency on a private maven repo. The database and redis host variables are injected into my app at runtime so they know which container to point to)
image: maven:3.5.0-jdk-8
before_script:
- "docker login -u$DOCKER_USER -p$DOCKER_PASS" #pipeline variables
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
DATABASE_HOST: mysql
REDIS_HOST: redis
services:
- name: privaterepo/private-mysql-schema
alias: mysql
- name: redis:latest
alias: redis
stages:
- build
maven-build:
stage: build
script: "mvn $MAVEN_CLI_OPTS package -B"
artifacts:
paths:
- target/*.jar
First thing is to setup GitLab CI to provide credentials of the private docker registry when needed. To do that there is specific section in docs you should follow, to be a complete answer that is
docker login
or some other manner (I had to spend sometime to figure out registry for the docker hub)DOCKER_AUTH_CONFIG
varialbe in GitLab CI variable section it would look like{ "auths":{ "registry.hub.docker.com":{ "auth":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx" // base 64 encoded username:password } } }
image: registry.hub.docker.com/ruwanka/helloworld:0.1
in.gitlab-ci.yml
That should full fill the requirement of pulling images. There is another section in docs that lists the requirement of runner to allow list of services. If it doesn't specify any then it should be fine, you may have to tweak it if it doesn't work.
final yaml is look like below
snippet of gitlab job's logs