Services not working. Can someone review my yaml?

I am adding MySQL as a service to a CentOS image, but when I try to use them in scripts they don’t work. What am I doing wrong?

image: centos
  stage: development
  - mysql
    MYSQL_DATABASE: el_duderino
    MYSQL_ROOT_PASSWORD: mysql_strong_password
  - mysql -h mysql -u root -p somefancypassword

Fundamental about docker services is that they are services: they are not installed on top of your image, but are accessible as a webservice alongside your image, so you can’t access them in a script like you’re trying to.

@bert.bruynooghe So have do I use MySQL as a service at all then? Everyone is telling me I can’t install it normally because Docker containers aren’t VMs, and that I should just link it using services. So how can I access it then?


things you execute in the script array are run in the build container. Think of building a Java software which uses jdbc to access data in a MySQL DB. Now for integration testing you need a MySQL server while for building such software you only need a JDK and e.g. Maven.

So you have one Docker image with Maven and Java for building and running tests (build container) and an arbitrary number of services (a running MySQL database server, memcached etc.) which you may access as if they were running on another host. The “hostname” (in reality the name of the linked docker container) is the same as the image name where the tag is stripped and slashes are replaced by hyphen, so a service organization/special-db would be reachable/pingable as organization-special-db from inside your build container. So the MySQL server in your example is reachable via TCP as “host” mysql at port 3306 HTH.

Just got it working. Simple answer for other people new at this: you need to install MySQL Client on your build container. This communicates to the MySQL service. If you simply add it as a service, you will get errors even if you use the correct host (mysql) and credentials.