Currently i am working on django app and trying to work with reddis server. i have add all configuration settings for reddis server in settings.py my settings are like this.
redis_host = os.environ.get('REDIS_HOST', 'my-ip-of-reddis-server')
# Channel layer definitions
# http://channels.readthedocs.org/en/latest/deploying.html#setting-up-a-channel-backend
CHANNEL_LAYERS = {
"default": {
# This example app uses the Redis channel layer implementation asgi_redis
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [(redis_host, 6380)],
},
"ROUTING": "multichat.routing.channel_routing",
},
}
its working fine when i run
python manage.py runser or python manage.py runworkers
but when i dockerize this django app, it does not make connection with reddis server. it gives following error.
redis.exceptions.ConnectionError: Error -2 connecting to redis:6380. Name or service not known.
2018-01-30 06:00:47,704 - ERROR - server - Error trying to receive messages: Error -2 connecting to redis:6380. Name or service not known.
201
My dockerfile is this.
# FROM directive instructing base image to build upon
FROM python:3-onbuild
RUN apt-get update
ENV PYTHONUNBUFFERED 1
ENV REDIS_HOST "redis"
# COPY startup script into known file location in container
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
#RUN python manage.py runserver
RUN daphne -b 0.0.0.0 -p 8000 --ws-protocol "graphql-ws" --proxy-headers multichat.asgi:channel_layer
# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!
and i have also tried this.
# FROM directive instructing base image to build upon
FROM python:3-onbuild
RUN apt-get update
ENV PYTHONUNBUFFERED 1
ENV REDIS_HOST "redis"
# COPY startup script into known file location in container
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
RUN python manage.py runserver
RUN daphne -b 0.0.0.0 -p 8000 --ws-protocol "graphql-ws" --proxy-headers multichat.asgi:channel_layer
# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!
But this is not making connection while containerizing my django app.
Can anybody please tell me, where i am wrong? how can i dockerize my django app that will make connection with redis server whose settings are places in settings.py. Any help or suggestion will be highly appreciated. Thanks.