Use docker dind with GitLab runner on ecs fargate
Asked Answered
M

1

6

I setup a GitLab runner on EC2 which triggers jobs on a Fargate ECS cluster. I followed this tutorial step by step: https://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate

During my CI/CD I build docker image then I want to reuse them during other stages of my CI/CD. So when I used shared runner I used docker dind:

  image: docker:stable
  services:
    - docker:dind

My config.toml looks like this:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "fargate-runner"
  url = "https://gitlab.com/"
  token = "KRGVsYCF-V-D1u7UvCjq"
  executor = "custom"
  builds_dir = "/opt/gitlab-runner/builds"
  cache_dir = "/opt/gitlab-runner/cache"
  [runners.custom]
    config_exec = "/opt/gitlab-runner/fargate"
    config_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "config"]
    prepare_exec = "/opt/gitlab-runner/fargate"
    prepare_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "prepare"]
    run_exec = "/opt/gitlab-runner/fargate"
    run_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "run"]
    cleanup_exec = "/opt/gitlab-runner/fargate"
    cleanup_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "cleanup"]

What should I do to use docker command during my CI/CD and to keep docker image of each build between all stages?

Misguide answered 16/3, 2022 at 13:37 Comment(3)
I don't think this is possible as the image will be stored locally them destroyed at this end of the stage. One option could be to use docker save/load to export the image as an artefact or cached folderGuanidine
I was thinking this too. To use docker save/load should I use docker dind or just install docker in my debian image that I use on ECS for each job?Misguide
You probably don't need dind as your base image is docker:stable, but I don't remember when dind is useful.Guanidine
M
5

docker:dind requires privileged execution. It is not possible to use privileged containers on Fargate, so this is not directly possible.

However, you may be able to use daemonless image builders, such as kaniko to build docker images and, optionally, use those images as the build image for later jobs.

You can also explore alternatives, like using CodeBuild to build images with the fargate executor.

Minimal answered 16/3, 2022 at 16:45 Comment(1)
Thank you, I will see which one is the best for me between kaniko and CodeBuildMisguide

© 2022 - 2024 — McMap. All rights reserved.