I try to build CI with mysql service and building my code with dind configuration.
But I end up with: Can’t connect to MySQL server on ‘mysql’
I’m not sure if services can be used like that with dind so they are accessible later from inside of builded docker containers?
My gitlab-ci config:
- docker build -t new_image .
- docker run new_image bundle exec rake db:create RAILS_ENV=test
I haven’t used dind but I’m using docker image one for gitlab and one for mysql and it’s working fine.
I have --network=host on mysql container but not for the gitlab to avoid port 22 conflict. In my my.cnf, had to allow mysql access from 172.17.0.2 or the ip of gitlab container ip address.
I didn’t even could reach it by network. I’m just not sure if when using dind, the other services are visible inside of the docker?
As i assume dind is for separation purposes for parallel tests, so i don’t think that it is good idea to use same database.
So the question is if this configuration should create mysql service for each instance of test suite?
Remembered. Gitlab puts a restriction on community edition about MySQL. I think I had problem with Gitlab docker image accessing external MySQL. Postgresql doesn’t have this restriction so I’ve switched to using Postgresql with my Gitlab docker. So, use Postgresql for each test suite?
Did you manage to fix this? I’m trying the same thing but it can’t even find the host: ERROR 2005 (HY000): Unknown MySQL server host ‘mysql’ (0). using mysql:latest
Hello, I meet the same problem. I can’t connect mysql db when running docker dind gitlab. Anyone fix this. Please help.
Hi, I’m experiencing the same thing here. I have a docker-in-docker service running, using the Gitlab MySQL service. I want by docker image during the build phase to connect to the mysql service. However, the error I get is the following:
Connection Error: Error: getaddrinfo ENOTFOUND mysql mysql:3306
And my Docker build command looks like the following
docker build --network=host -t $REPOSITORY_URL:latest .
I thought network=host would do the trick, but apparently not?
Please help, this is the last step I need to overhome - running db integration tests as part of my CI with docker containers!
Hi @albertkim , I know it’s been a while, but did you ever find a solution to this problem?
I’m having a very similar issue with the Redis service and was hopeing you perhaps had an answer.
thank you for your time.
Hi all. Same problem. I am using GitLab on-premises. Two gitlab-ci.yml services: mysql and docker:dind.
# Run tests
- ping mysql -c 4
- docker run --name dummy -e DB_HOST=mysql devimage vendor/bin/phpunit --configuration phpunit.xml --coverage-text --colors=never --log-junit /tmp/report.xml
docker run, my container cannot connect to mysql service. Running
ping mysql outside the container, at the same level as
docker run, ping works. But inside container mysql is not available. It is not able to resolve the host name. Is there any solution, or this is a limitation?