I'm trying to use DinD (Docker in Docker) with my Gitlab-CI build script and I keep getting the same error not matter what I change. What am I doing wrong?
Errors
Service container logs:
2018-08-21T22:54:00.129660274Z mount: permission denied (are you root?)
2018-08-21T22:54:00.129701426Z Could not mount /sys/kernel/security.
2018-08-21T22:54:00.129706380Z AppArmor detection and --privileged mode might break.
2018-08-21T22:54:00.130334774Z mount: permission denied (are you root?)
...
$ docker info
error during connect: Get http://docker:2375/v1.38/info: dial tcp: lookup docker on 8.8.8.8:53: no such host
gitlab-ci.yml
django_build:
stage: build
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
image: docker:stable
services:
- docker:dind
before_script:
- docker info
script:
- echo "Building something."
gitlab-runner config.toml
concurrent = 1
check_interval = 0
[[runners]]
name = "###"
url = "###"
token = "###"
executor = "docker"
[runners.docker]
tls_verify = false
image = "alpine:3.4"
privileged = true
disable_cache = false
volumes = ["/cache"]
[runners.cache]
Insecure = false
/etc/docker/daemon.json
{
"storage-driver": "overlay2"
}
---EDIT---
For anyone that comes back to look at this here's how I got it working. I was running the gitlab-runner on my local machine to test things before committing to the repo.
When running the command:
gitlab-runner exec docker django_build
for whatever reason it wasn't using my config file. I found this link: https://gitlab.com/gitlab-org/gitlab-runner/issues/1791 stating that you have to out --docker-privileged in the command.
After running:
gitlab-runner exec docker --docker-privileged django_build
everything worked.
Double-check the GitLab runner parameters when running docker.
In particular, do make sure the gitlab-runner
user is added to docker group:
sudo usermod -aG docker gitlab-runner
From there, sudo -u gitlab-runner -H docker info
should work.
If not, check if the /etc/hosts
is mounted as a volume, as in this bug.
The official gitlab-runner documentation states, for DiD executor, to create a config.toml with
[[runners]]
url = "https://gitlab.com/"
token = TOKEN
executor = "docker"
[runners.docker]
tls_verify = false
image = "docker:stable"
privileged = true
But the OP has found the privileged = true
is not used.
Unless maybe if the config.tml was created by a sudo gitlab-runner register -n... --docker-privileged
command.
If not, gitlab-runner exec docker --docker-privileged
is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With