When using GitLab CI, as well as the gitlab-ci-multi-runner
, I\'m unable to get internally-started Docker containers to expose their ports to the \"host\", whic
Usually a docker machine won't run on localhost, but on a docker host with some other ip address. Try using docker-machine ip
to get your docker host ip.
When using docker:dind
a container is created and your docker-compose containers get setup within it. It exposes the ports to localhost within the docker:dind
container. You cannot access this as localhost
from the environment that your code is executing in.
A hostname of docker
is setup for you to reference this docker:dind
container. You can check by using cat /etc/hosts
.
Instead of referencing localhost:9143
you should use docker:9143
.
Your docker-compose.yml
seems to be ok.
But I think there is error with your ip or port routing. As I can see from your shared info your app is running on port 9143 on ip 0.0.0.0 as 0.0.0.0:9143.
and you are accessing it as localhost:9143
,
which can be interpreted as 127.0.0.1:9143
.
According to this.
127.0.0.1 is the loopback address (also known as localhost).
0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder).
Can you try to run your app on 127.0.0.1:9143
then share the result.
UPDATE
or you can use service to run it by service name as documentation suggest:
The services keyword defines just another docker image that is run during your build and is linked to the docker image that the image keyword defines. This allows you to access the service image during build time.
The service container for MySQL will be accessible under the hostname mysql
.
So, in order to access your database service you have to connect to the host named mysql instead of a socket or localhost
.
The offical gitab-ci on gitlab.com documentation refers to the example of PostgreSQL
Its working CI does not try to connect to localhost, but rather to the service name
The
services
keyword defines just another docker image that is run during your build and is linked to the docker image that the image keyword defines. This allows you to access the service image during build time.The service container for MySQL will be accessible under the hostname
mysql
.
So, in order to access your database service you have to connect to the host namedmysql
instead of a socket orlocalhost
.
You could check if this applies in your case, and try accessing your application service in app:9143
instead of localhost:9143
.