Hi:
We try to running Redis service for application testing in build process, however, something wrong when application try to connect to Redis, from below code section, all steps works fine except “ping redis in docker”, the main different for this step is we build a py file to docker, and run it to get/set data from Redis, but it shows up error message like "redis.exceptions.ConnectionError: Error -2 connecting to cache:6379. Name or service not known."
Does anyone have idea about how to proceeding this? thanks
.drone.yml
kind: pipeline
name: App-report
platform:
os: linux
arch: amd64
steps:
- name: ping redis
image: redis
commands:
- sleep 5
- redis-cli -h cache ping
- redis-cli -h cache set FOO bar
- redis-cli -h cache get FOO
- name: ping mongo
image: mongo:3
commands:
- sleep 5
- mongo --host mongo --eval "db.version()"
- name: ping pyredis
image: python:3.7-slim
commands:
- pip3 install redis
- python3 test_redis.py
- name: ping redis in docker
image: docker:dind
volumes:
- name: dockersock
path: /var/run
commands:
- docker build -t myredis-docker -f redis_Dockerfile .
- docker run -itd --rm --name myredis-docker myredis-docker
- docker logs -f myredis-docker
- docker stop myredis-docker
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
- name: cache
image: redis
ports:
- 6379
- name: mongo
image: mongo:3
command: [ --smallfiles ]
ports:
- 27017
volumes:
- name: dockersock
temp: {}
test_redis.py
import redis
if __name__ == '__main__':
r = redis.from_url('redis://cache')
print (r.ping())
print (r.get('FOO'))
print (r.set('z', 'xyz'))
print (r.get('z'))
redis_Dockerfile
FROM python:3.7-slim
ADD test_redis.py /
RUN pip install redis
CMD [ "python", "./test_redis.py" ]