With all the noise around those topics I would have imagined this one had been covered thousands of time, yet I did not find a single complete resource on this subject which I found to be a basic building block: pushing docker images from GitLab CI to the Docker Hub registry.
There’s actually an opened issue on Docker GitHub‘s that’s sitting there for 3 years, and it really feels more like a political / strategic / commercial issue than a technical one. Point being, there’s no straightforward integration between GitLab.com and Docker Hub.
I really don’t like the method that’s been used by all the people in the same situation but I just can’t find any other one: you basically have to create variables within GitLab.com‘s CI settings with your Docker Hub login and password. This looks like this :
One more catch, the
$CI_REGISTRY is the value found in
docker info|grep -i registry:, here being
https://index.docker.io/v1/. Thanks to this post for the hint.
Once the credentials and endpoint set, you can write a
.gitlab-ci.yml file that looks like this:
I didn’t find GitLab documentation impressive on how to use the CI in their very own website, here are some pointers :
$IMAGE_TAG variable, you could replace
$CI_PROJECT_NAME if the project has the same name on Docker Hub and GitLab (which is a good idea).
$CI_COMMIT_TAG is set when an actual
tag is pushed, so this is triggered this way:
$ git commit -m "things changed" foo .gitlab-ci.yml
This will summon the CI / CD pipeline with a
$CI_COMMIT_TAG value of
0.27 , hopefully build the docker image and push it to Docker Hub.
Do you have another solution? Please tell me in the comments!