skip to Main Content

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


  1. Chosen as BEST ANSWER

    I am putting here a solution if anyone else has the same problem.

    The redis service in gitlab-ci.yml works as follows:

    1. Gitlab runner starts the redis-server in the user image.
    2. The redis server can only be connected by the ip-address of your container(the first one, not docker assigned).
    3. Pass the ip-address mentioned above to python code(replace "redis" with "$ip")

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search