-
Notifications
You must be signed in to change notification settings - Fork 83
Fix Redis Connection and Docker Configuration for Gin Application #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@dev-priyanshu15 , People also use docker containers to talk to application natively, this PR doesnt support that, instead you can add a doc and add these things |
Thanks for the feedback! I have already addressed the issue regarding native communication between Docker containers and the application in the updated documentation. I included the necessary configurations and guidelines for using the container name to establish communication within the Docker network. Please check the "Native Communication between Docker Containers and Application" section in the updated README for more details. Let me know if you would like any further improvements or additions! |
Signed-off-by: dev-priyanshu15 <[email protected]>
… Docker Compose configuration Signed-off-by: dev-priyanshu15 <[email protected]>
No significant project changes found. For retrying, please click here |
To generate Unit Tests for this PR, please click here |
|
Fix: Redis Connectivity Issues in Dockerized Gin Application
Description:
This PR addresses and fixes the connectivity issues between the Gin application and Redis when running within a Docker environment. The primary issues were related to:
Problem 1: Redis Connection Settings in Go Application
Issue:
The Go application was originally configured to connect to Redis using:
Addr: "localhost:6379"
This configuration works when running the application locally (without Docker) but fails in a containerized environment because:
localhost
points to the container itself, not the Redis service.Solution:
Updated the Redis address in the application code to:
Addr: "redis:6379"
Here,
redis
matches the service name defined indocker-compose.yml
, allowing the application to connect properly within the Docker network.Problem 2: Docker Compose Configuration
Issue:
The previous Docker Compose setup did not properly manage the dependency between the Go application and the Redis server.
depends_on
directive does not guarantee that the Redis container will be fully initialized before the Go application starts.Solution:
Improved the
docker-compose.yml
to properly manage service dependencies:Key Improvements:
depends_on
to ensure that Redis starts before the Go application.REDIS_HOST=redis
andREDIS_PORT=6379
for flexible and dynamic configuration.redis
as the hostname to leverage Docker’s internal DNS resolution.Testing:
http://localhost:3001
.Future Improvements: