Error connecting to Redis on redis:6379 (SocketError) at aws, ecs
I am using Rails 6 with sidekiq and redis:
The Redis container starts, but the Sidekiq container does not start:
My Docker configuration is as:
version: '3'
services:
redis:
image: redis:alpine
container_name: redis
command: redis-server --bind 0.0.0.0
ports:
- "6379:6379"
networks:
appnet:
aliases:
- redis
healthcheck: # Crucial for AWS/Sidekiq stability
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
opal_web:
build: .
container_name: opal_web
command: >
bash -c "
until nc -z redis 6379; do
echo 'Waiting for redis...'
sleep 1
done;
rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'
"
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
redis:
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
REDIS_URL: redis://redis:6379/0
DATABASE_HOST: host.docker.internal
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: opal_04_09_2025
networks:
- appnet
opal_sidekiq:
build: .
container_name: opal_sidekiq
command: >
bash -c "
until nc -z redis 6379; do
echo 'Waiting for redis...'
sleep 1
done;
bundle exec sidekiq -C config/sidekiq.yml
"
volumes:
- .:/app
depends_on:
redis:
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
REDIS_URL: redis://redis:6379/0
DATABASE_HOST: host.docker.internal
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: opal_04_09_2025
networks:
- appnet
networks:
appnet:
driver: bridge
The containers are communicating with each other fine when starting the docker container in local host machine.
But when deploying to ECS after uploading the images, it's giving the following error:
Redis::CannotConnectError at /
Error connecting to Redis on redis:6379 (SocketError)