The scene is very basic. There is a dockerfile on gitlab server and this repository is build by gitlab-runner using docker. There is a my pipeline:
image: docker:latest
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:dind
alias: docker
stages:
- build
- test
build:
stage: build
script:
- docker build -t swim-web-img .
tags:
- docker
- dotnet
test:
stage: test
script:
- docker run -dp 8080:80 --name swim-web-cntr swim-web-img
tags:
- docker
- dotnet
This is a create docker image but gitlab-runner can not find during build and test job:
Running with gitlab-runner 15.10.1 (dcfb4b66)
on kmaster mA_Dauog, system ID: r_oo2GNSfyvuPo
Preparing the "docker" executor
00:32
Preparing environment
00:01
Running on runner-madauog-project-2-concurrent-0 via kmaster...
Getting source from Git repository
00:01
Executing "step_script" stage of the job script
01:14
Using docker image sha256:1be445cc553ebefc75d9f4917065d9e94c21bc731bdffab90cde482469d9e4a7 for docker:latest with digest docker@sha256:c20b7d2415de59f308553646712d9b1d92f4186aeaf8b04afae7f42129dab425 ...
$ docker build -t swim-web-img .
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 736B done
...
#18 naming to docker.io/library/swim-web-img done
#18 DONE 0.2s
WARNING: buildx: git was not found in the system. Current commit information was not captured by the build
Job succeeded
Test job return Unable to find image 'swim-web-img:latest' locally failed message and after try to login docker hub.
Running with gitlab-runner 15.10.1 (dcfb4b66)
on kmaster mA_Dauog, system ID: r_oo2GNSfyvuPo
Preparing the "docker" executor
00:29
Preparing environment
00:01
Getting source from Git repository
00:01
Executing "step_script" stage of the job script
00:03
Using docker image sha256:1be445cc553ebefc75d9f4917065d9e94c21bc731bdffab90cde482469d9e4a7 for docker:latest with digest docker@sha256:c20b7d2415de59f308553646712d9b1d92f4186aeaf8b04afae7f42129dab425 ...
$ docker run -dp 8080:80 --name swim-web-cntr swim-web-img
Unable to find image 'swim-web-img:latest' locally
docker: Error response from daemon: pull access denied for swim-web-img, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
ERROR: Job failed: exit code 125
Additionaly I can not appear this image docker image ls
output:
REPOSITORY TAG IMAGE ID CREATED SIZE
docker dind 1be445cc553e 12 hours ago 318MB
docker latest 1be445cc553e 12 hours ago 318MB
registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper x86_64-dcfb4b66 217a980e5a21 3 days ago 64.6MB
ruby 2.7 82ca169bb3c4 6 days ago 865MB
mcr.microsoft.com/dotnet/sdk 7.0 fa397c19e0b5 6 days ago 775MB
docker <none> e072c2e5e550 13 days ago 318MB
Each job has its own independent docker daemon (as declared in your services:
). Therefore, you cannot build and run the same image across jobs. When the job completes, the docker:dind
service (the job's docker daemon) shuts down and any images pulled or built in the job are also removed.
You should either build and run the container in the same job or push the container image to a registry first and then pull it in the subsequent job.