2

I'm currently trying to setup a gitlab ci pipeline. I've chosen to go with the Docker-in-Docker setup. I got my ci pipeline to build and push the docker image to the registry of gitlab but I cannot seem deploy it using the following configuration:

.gitlab-ci.yml

image: docker:stable
services:
- docker:dind

stages:
- build
- deploy

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2
  TEST_IMAGE: registry.gitlab.com/user/repo.nl:$CI_COMMIT_REF_SLUG
  RELEASE_IMAGE: registry.gitlab.com/user/repo.nl:release

before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker info

build:
  stage: build
  tags:
  - build
  script:
  - docker build --pull -t $TEST_IMAGE .
  - docker push $TEST_IMAGE
  only:
  - branches

deploy:
  stage: deploy
  tags:
  - deploy
  script:
  - docker pull $TEST_IMAGE
  - docker tag $TEST_IMAGE $RELEASE_IMAGE
  - docker push $RELEASE_IMAGE
  - docker run -d --name "review-$CI_COMMIT_REF_SLUG" -p "80:80" $RELEASE_IMAGE
  only:
  - master
  when: manual

When I run the deploy action I actually get the following feedback in my log, but when I go check the server there is no container running.

$ docker run -d --name "review-$CI_COMMIT_REF_SLUG" -p "80:80" $RELEASE_IMAGE
7bd109a8855e985cc751be2eaa284e78ac63a956b08ed8b03d906300a695a375
Job succeeded

I have no clue as to what I am forgetting here. Am I right to expect this method to be correct for deploying containers? What am I missing / doing wrong?

tldr: Want to deploy images into production using gitlab ci and docker-in-docker setup, job succeeds but there is no container. Goal is to have a running container on host after deployment.

1 Answer 1

1

Found out that I needed to include the docker socket in the gitlab-runner configuration as well, and not only have it available in the container. By adding --docker-volumes '/var/run/docker.sock:/var/run/docker.sock' and removing DOCKER_HOST=tcp://docker:2375 I was able to connect to docker on my host system and spawn sibling containers.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm faced something similar. I want to deployed using shell executor. where I suposse I could add --docker-volumes?. on config.toml? How?
Hi @Darwin. The docker volumes need to be on the docker-compose file if you are using it, otherwise on the docker run command. But also in the config.toml as volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.