My gitlab-ci.yml looks like this:
stage: functional_test
only:
- develop
- master
- merge_requests
services:
- redis:latest
- docker:18.06.2-dind
variables:
PHOTON_ENV: development
DOCKER_HOST: tcp://localhost:2375
REDIS_HOST: redis
REDIS_URL: redis://redis:6379/0
And my python code to connect redis looks like this:
self._redis = redis.Redis(host=_host,
port=_port,
db=_db,
decode_responses=True)
_host = 'redis'
_port = 6379
_db = 0
However, every time I try this code, this error will show up:
File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 772, in execute_command
403 connection = pool.get_connection(command_name, **options)
404 File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 994, in get_connection
405 connection.connect()
406 File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 497, in connect
407 raise ConnectionError(self._error_message(e))
408 redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name or service not known.
2
Answers
I am putting here a solution if anyone else has the same problem.
The redis service in gitlab-ci.yml works as follows:
Going from comments and according to documentation you have to manually install redis on your gitlab runner server if you are using a shell executor.