Reputation: 2121
I am trying to configure Gitlab CI for my dockerized Symfony project.
In the test phase, I try to start my docker-compose.yml, where one service needs a bind mount. My runner does see the folder, but I cannot use it. I get as test output:
$ docker-compose -f docker-compose_deploy.yml up -d
Creating network "xxx_default" with the default driver
Creating xxx_php_1 ...
Creating xxx_db_1 ...
Creating xxx_php_1 ... done
Creating xxx_nginx_1 ...
Creating xxx_db_1 ... error
ERROR: for xxx_db_1 Cannot start service db: Bind mount failed: '/backups' does not exists
To test that I included the command ls /
in my before_script
section. But it does show /backups
, since I altered my runners' config.toml:
[[runners]]
name = "main-runner"
url = "https://gitlab.com/"
token = "xyz"
executor = "docker"
[runners.docker]
tls_verify = false
image = "docker:latest"
privileged = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock","/volume1/docker/postgres-backup:/backups", "/cache"]
shm_size = 0
[runners.cache]
Here's the important part of my .gitlab-ci.yml
:
before_script:
- ls /
- docker info
- apk add --update py-pip && pip install docker-compose
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
build:
stage: build
script:
- docker-compose -f docker-compose_deploy.yml build --pull
test1:
stage: test
script:
- docker-compose -f docker-compose_deploy.yml up -d
- docker exec registry.gitlab.com/xxx-group/xxx_php_1 bash docker/php-fpm/initialization.sh
- docker exec registry.gitlab.com/xxx-group/xxx_php_1 bin/console app:initialize
- docker exec registry.gitlab.com/xxx-group/xxx_php_1 ./vendor/bin/simple-phpunit
after_script:
- docker-compose -f docker-compose_deploy.yml down
The docker-compose.yml is
volumes:
pgdata:
services:
db:
image: postgres:9-alpine
volumes:
- pgdata:/var/lib/postgresql/data
- /backups:/backups
Although the built images cannot be executed, I can inspect
them:
And the volume in fact is not listed there!
"Volumes": {
"/var/lib/postgresql/data": {}
}
Upvotes: 0
Views: 3135
Reputation: 2121
To repeat Stefan von Gastel's correct answer:
When running the test (and docker-compose'ing up
), in my setting, the docker commands run in the context of the docker host, i.e. the machine that executes the gitlab-runner.
So to stay in my config, a simple
$ ln -s /volume1/docker/postgres-backup/ /backups
solved my problem, because now the path is available. In fact, the entry in volumes
in my runner's config.toml
are unneccessary.
THANKS Stefan!
Upvotes: 1
Reputation: 4478
You are running docker-in-docker with a shared socket. This means that you have a Gitlab CI runner host (a.k.a HOST) and a job running in a container based on docker:latest
(a.k.a JOBCONTAINER).
Your assumption is that you can mount files that exist in your JOBCONTAINER (the ones you see when you ls
in your before_script
) when in fact the actual container you are starting with docker-compose
will run in context of the HOST since you are using its Docker daemon inside your JOBCONTAINER.
Upvotes: 4