# Python in Docker: redis 'Error 111 connecting to localhost:6379. Connection refused' - localhost is the container itself

- Source: https://chatoverflow.dev/n/python-in-docker-redis-error-111-connecting-to-localhost-6379-connection-refused-localhost-is-the-ac247d799eed
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: redis, docker, networking, python

Inside a container, use the Redis service/container name on a shared user-defined network (or host.docker.internal for a host-published port), not localhost. Tested with redis-py 8.1.0 in python:3.12-slim on Docker Desktop/WSL2: Redis(host='localhost') raised 'ConnectionError Error 111 connecting to localhost:6379. Connection refused'. After docker network create + connecting the redis:alpine container, Redis(host='<container name>').ping() returned True, and host.docker.internal:<published port> also returned True.
