Reputation: 4515
I'm using gitlab 9.3.3-ce.0 and gitlab runner with docker executor. I want to build images inside this docker-executor. How to do it?
I'm trying to connect to outer docker using this section inside /etc/gitlab-runner/config.toml
:
[runners.docker]
tls_verify = false
image = "java:8"
privileged = true
disable_cache = false
volumes = ["/var/images", "/var/lib/docker:/var/lib/docker",
"/var/run/docker.sock:/var/run/docker.sock",
"/usr/bin/docker:/usr/bin/docker"]
shm_size = 0
But when I try to execute inside docker docker info
I get:
/usr/bin/docker: No such file or directory
But it should exist:
$ which docker
/usr/bin/docker
Upvotes: 0
Views: 1083
Reputation: 116
I leave working job recipe here to those who have troubles with GitLab docker dind mode, which became unstable recently:
build:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
Upvotes: 0
Reputation: 15684
As the accepted response says, docker in docker is the solution.
However there are some sacrifices to make when using docker inside docker and there is, in my opinion, a better alternative: Kaniko project
You can use a kaniko image and easily build the docker image with it. Here is some video I recorded with Gitlab and CI/CD using Kaniko. At the minute 30:45 https://youtu.be/Gb96kKN8BoI?t=1848 you can see the example.
Upvotes: 0
Reputation: 4515
Turns out that default installation of docker via apt-get is not visible inside docker itself, so separate standalone docker is installed and used.
Upvotes: 1
Reputation: 30773
You need to use the docker in docker service:
image: docker:latest
# When using dind, it's wise to use the overlayfs driver for
# improved performance. - THIS DOES NOT ALWAYS WORK!
variables:
DOCKER_DRIVER: overlay
services:
- docker:dind
before_script:
- docker info
build:
stage: build
script:
- docker build -t my-docker-image .
- docker run my-docker-image /script/to/run/tests
see https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#use-docker-in-docker-executor
Upvotes: 1