docker-windows
installedAll build scripts that don't rely on services run fine.
Now I want to use mysql as a service for my integration tests. I already build a custom mysql container that I can use.
In the past I used the same setup with docker on linux. So this is something that definitely should work.
The problem is that my container can't resolve or ping the hostname db. I already attached to my build container and the mysql container to determine the ip-addresses and verified that they can ping each other.
build-container-ip: 172.25.177.32
mysql-container-ip: 172.25.187.223
I would except that the build container can resolve the mysql container with the hostname db
but that's not the case. See gitlab services
I am not sure if this is an issue with gitlab docker runner or with docker on windows. I'm very confident that the build script itself is fine. How can I track down or solve the problem? My build container needs to know the ip of the service.
stages:
- build
build:
image: registry.company.tld/company/build-images/devenv:latest
stage: build
tags:
- windows
- docker
services:
- name: registry.company.tld/company/build-images/mysql-win:latest
alias: db
variables:
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
script:
- mysqlping -h db
relevant output
C:\mysql\bin\mysqladmin.exe: connect to server at 'db' failed
error: 'Unknown MySQL server host 'db' (2)'
Check that mysqld is running on db and that the port is 3306.
You can check this by doing 'telnet db 3306'
What I can tell by using docker inspect
"Config": {
"Hostname": "runner-gkokct4y-project-10-concurrent-0",
"Domainname": "",
"Config": {
"Hostname": "ee98c58eed41",
"Domainname": "",
I figured it out myself. The solution is in the section connecting services
For this solution to work, you must use the networking mode that creates a new network for each job.
TLDR: You have to set the feature flag FF_NETWORK_PER_BUILD
either on runner level (in config.toml)
[[runners]]
(...)
executor = "docker"
environment = ["FF_NETWORK_PER_BUILD = 1"]
Or:
[[runners]]
(...)
executor = "docker"
[runners.feature_flags]
FF_NETWORK_PER_BUILD = true
or in your gitlab-ci.yml
file
stages:
- build
build:
image: registry.company.tld/company/build-images/devenv:latest
stage: build
tags:
- windows
- docker
services:
- name: registry.company.tld/company/build-images/mysql-win:latest
alias: db
variables:
FF_NETWORK_PER_BUILD: 1
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
script:
- mysqlping -h db
I set it in the gitlab-ci.yml
file and it instantly worked as expected. In the past I only used this setup on gitlab-runner in kubernetes. Since the docs for the feature flag explicitly mention docker executor
Enables creation of a Docker network per build with the docker executor
I guess that's the default behavior for kubernetes runner.
So in contrast to my initial assumption, that the issue is related to docker on windows, it possibly wouldn't have worked on linux docker either. So I'll rephrase the title to reflect that.