Skip to content

Instantly share code, notes, and snippets.

@andreyka26-git
Last active February 8, 2023 12:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreyka26-git/e8eccb8d9df8d893b0bd391816c017a0 to your computer and use it in GitHub Desktop.
Save andreyka26-git/e8eccb8d9df8d893b0bd391816c017a0 to your computer and use it in GitHub Desktop.
GitLab runner in docker (using dind) with sample gitlab.ci set up
** run these commands inside your machine
docker run -v /srv/gitlab-runner/config:/etc/gitlab-runner --name runner -v /var/run/docker.sock:/var/run/docker.sock -d gitlab/gitlab-runner
docker exec -it runner bash
gitlab-runner register -n \
--url "https://gitlab.com/" \
--registration-token "qSf6YzdsXjMug69WxVTt" \
--executor "docker" \
--docker-image alpine:latest \
--docker-privileged \
--description "ubuntu-dind-runner" \
--tag-list "ubuntu-dind-runner" \
--run-untagged="true"
gitlab-runner start
exit
** sample gitlab-ci.yml (if you would like to add versions to images - keep 'docker:dind' service and 'docker:stable' with the same versions)
variables:
DOCKER_HOST: tcp://thedockerhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
build_image:
stage: build
services:
- name: docker:dind
alias: thedockerhost
image:
name: docker:stable
script:
- docker login -u <username> -p $REGISTRY_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH .
- docker push $CI_REGISTRY/$CI_PROJECT_PATH
- echo "image was built and pushed."
- docker logout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment