.gitlab-ci.yaml use image with a specific user
git - Multiple Docker images in .gitlab-ci.yml - Stack Overflow
Use your own image on GitlabCI
How to put multiple images in image keyword in gitlab-ci - Stack Overflow
You can define the image to use per job.
For instance:
before_script:
- apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
- apt-get install --yes libarchive-dev liblzma-dev
build:precise:
image: precise:base
script:
- mkdir build/
- cd build
- cmake -D CMAKE_BUILD_TYPE=Debug ../
- make
build:trusty:
image: trusty:base
script:
- mkdir build/
- cd build
- cmake -D CMAKE_BUILD_TYPE=Debug ../
- make
Your can use Anchors to make the .gitlab-ci.yml more clearly. (But this need GitLab 8.6 and GitLab Runner v1.1.1.)
Like this:
before_script:
- apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
- apt-get install --yes libarchive-dev liblzma-dev
.build_template: &build_definition
script:
- mkdir build/
- cd build
- cmake -D CMAKE_BUILD_TYPE=Debug ../
- make
build:precise:
image: precise:base
<<: *build_definition
build:trusty:
image: trusty:base
<<: *build_definition
Since multi architecture/platform tags of a Docker image have different digests, You can pull a Docker image using its digest (instead of using tags) to pull the desired architecture/platform.
Here is an example of multi architecture/platform tag of a Docker image (Ubuntu) in Docker Hub:
As you can see, 20.04 is a multi architecture tag and there are different digests for each of architectures in the tag.
If you run command docker pull ubuntu:20.04
it will pull all architectures.
But command
docker pull ubuntu@sha256:55e5613c8c7bcd8044aaf09d64d20518964a0d7a6e41af129f95b731301c2659
will pull just linux/arm/v7.
As I tried, it is possible to use digest in .gitlab-ci.yml:
job_1:
image: ubuntu@sha256:55e5613c8c7bcd8044aaf09d64d20518964a0d7a6e41af129f95b731301c2659
script:
- ...
job_2:
image: alpine@sha256:71465c7d45a086a2181ce33bb47f7eaef5c233eace65704da0c5e5454a79cee5
script:
- ...
Speaking of image digest, GitLab 13.5 (October 2020) proposes:
Create release with image digest on new tag
Docker supports immutable image identifiers and we have adopted this best practice to update our cloud-deploy images.
When a new image is tagged, we also programmatically retrieve the image digest upon its build, and create a release note to effectively communicate this digest to users.
This guarantees that every instance of the service runs exactly the same code.
You can roll back to an earlier version of the image, even if that version wasn’t tagged (or is no longer tagged). This can even prevent race conditions if a new image is pushed while a deploy is in progress.
See Documentation and Issue.
The only thing needed to access docker images from another project on the same gitlab instance is that your project is allowed for Token Access on the project with the image.
No other configuration like docker login is needed. Just use image: $CI_REGISTRY/other/project:tag
job-in-project1:
stage: test
image: $CI_REGISTRY/group-b/otherproject:latest
script:
- command to run with docker image
Configuration:
- Go to the project wich contains the image in its Container Registry. e.g.
group-b/otherproject - Open Settings > CI/CD
- Expand "Token Access"
- in Allow CI job tokens from the following projects to access this project click "Add Project"

Right now it is possible to use images from your gitlab registry without any special steps. Just build and push an image to your gitlab project container registry
docker build -t registry.gitlab.com/gitlabProject/projectName:build .
docker push registry.gitlab.com/gitlabProject/projectName:build
and then just specify this image in your pipeline settings:
image: registry.gitlab.com/gitlabProject/projectName:build
Gitlab is able to pull this image using it's credentials:
Preparing the "docker+machine" executor
00:46
Using Docker executor with image registry.gitlab.com/gitlabProject/projectName:build ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/gitlabProject/projectName:build ...
Using docker image sha256:e7e0f4f5fa8cff8a93b1f37ffd7dd0505946648246aa921dd457c06a1607304b for registry.gitlab.com/gitlabProject/projectName:build ...
More: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#support-for-gitlab-integrated-registry
