问题
https://docs.gitlab.com/ci/docker/using_docker_build/
- VPS 中建议使用
shell
模式,不用再特意配置。
- 若使用
docker
模式,需要修改以下几个配置:
.gitlab-ci.yml
中 HEALTHCHECK_TCP_PORT 和 HEALTHCHECK_TCP_PORT 必须配置。
services:
- name: docker:dind
variables:
HEALTHCHECK_TCP_PORT: "2375"
variables:
DOCKER_TLS_CERTDIR: ""
config.toml
配置文件中,必须将 privileged** 设置为 true
。
[runners.docker]
tls_verify = false
image = "docker:latest"
privileged = true
仓库文件 .gitlab-ci.yml
default:
image: docker:latest
services:
- name: docker:dind
variables:
HEALTHCHECK_TCP_PORT: "2375"
before_script:
- docker info
variables:
# When using dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket.
# DOCKER_HOST: tcp://docker:2375
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/services/#accessing-the-services.
# If you're using GitLab Runner 12.7 or earlier with the Kubernetes executor and Kubernetes 1.6 or earlier,
# the variable must be set to tcp://localhost:2376 because of how the
# Kubernetes executor connects services to the job container
# DOCKER_HOST: tcp://localhost:2376
#
# This instructs Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
build:
stage: build
script:
- docker build -t my-docker-image .
services:
- name: docker:dind
command: ["--registry-mirror", "https://registry-mirror.example.com"] # Specify the registry mirror to use
完整的 config.toml
concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "vps"
url = "https://gitlab.com"
id = 2279
token = "glrt-t3_xxdh3sLxT_uKXswNvxcW"
token_obtained_at = 2025-03-14T18:30:46Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[[runners]]
name = "docker"
url = "https://gitlab.com"
id = 2280
token = "glrt-t3_S2EG2tBQYKJfsismyHzZ"
token_obtained_at = 2025-03-14T18:34:57Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
network_mtu = 0
# 或者直接在 `config.toml` 里配置好 `services`
# 则 .gitlab-ci.yml 中不需要再另外配置 `services` 部分
[[runners.docker.services]]
name = "docker:dind"
# alias = "docker"
command = ["--registry-mirror", "https://docker.m.daocloud.io" ]
environment = ["HEALTHCHECK_TCP_PORT=2375"]