9

I am using docker executor on gitlab runner as an image I am using docker:stable I am getting this error:

$ docker login gitlab.mydomain.com:5050 -u myusername-p mytoken
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on 67.207.67.3:53: no such host
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Here is my config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "dev-env"
  url = "https://gitlab.mydomain.com/"
  token = "REDACTED"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0

Here is my ci file

deploy-dev:
  stage: deploy
  before_script:
    - apk add make
  script:
    - docker login gitlab.mydomain.com:5050 -u myusnerma -p mytoken
  only:
    - mybranch
  tags:
    - dev
Brandon Kauffman
  • 1,515
  • 1
  • 7
  • 33
Muhammadsiddiq
  • 275
  • 1
  • 2
  • 12

2 Answers2

15

You must add the docker:dind service to your job configuration:

deploy-dev:
  variables:
    # these values may need to be different if using TLS, k8s, etc.
    # You can alternatively set defaults in your runner config
    DOCKER_TLS_CERTDIR: ""
    DOCKER_HOST: "tcp://docker:2375"
  services:
    - docker:dind
  # ...

For the dind container to work, your runner must allow privileged containers:

  [runners.docker]
    privileged = true
    # ...
sytech
  • 29,298
  • 3
  • 45
  • 86
  • Following the comments on this issue https://gitlab.com/gitlab-org/gitlab-foss/-/issues/65511 I also had to unset the DOCKER_HOST variable to make it work – validname Sep 26 '22 at 08:35
3

Beside privileged = true you should also map /var/run/docker.sock inside docker container to /var/run/docker.sock on host. something like this:

concurrent = 1
check_interval = 0
[session_server]
  session_timeout = 1800
[[runners]]
  name = "my-runner"
  url = "https://gitlab.mydomain.com/"
  token = "GITLAB_RUNNER_TOKEN"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

More info from techoverflow

mehdiMj
  • 101
  • 8
  • 1
    You should NOT map the docker socket if you intend to use the `dind` service. Mounting the docker socket gives jobs access directly to the host docker daemon, which can have a number of negative impacts, but you won't need the `docker:dind` service in that case. – sytech Jan 26 '23 at 21:25