title: Can't connect to Redis Stack from GO application inside a container
body: <p>I have a GO REST API application and using redis stack and postgreSQL as main databases. I am able to connect to the postgres database but cannot connect to the redis stack database, it refuses to connect for some reason (it works on local development but refuses to connect inside the container). Here is my code to connect and my docker-compose file for reference.</p>
  <p>Connection to Redis Stack Code (Using <a href="https://pkg.go.dev/github.com/nitishm/go-rejson" rel="nofollow noreferrer">go-rejson</a> Package)</p>
  <pre><code>func getRedisDbConnection() (*redis.Client, *rejson.Handler) {
  redisDb := redis.NewClient(&amp;redis.Options{
      Addr:     viper.GetString(&quot;REDIS_DB_HOST&quot;) + viper.GetString(&quot;REDIS_DB_PORT&quot;),
      Password: viper.GetString(&quot;REDIS_DB_PASSWORD&quot;),
      DB:       viper.GetInt(&quot;REDIS_DB_NAME&quot;),
  })
  _, err := redisDb.Ping().Result()
  if err != nil {
      log.Println(&quot;Can't connect with Redis database&quot;, &quot;Errors:&quot;, err)
  } else {
      log.Println(&quot;Redis Db is connected&quot;, &quot;Errors:&quot;, err)
  }
  redisJsonDb := rejson.NewReJSONHandler()
  redisJsonDb.SetGoRedisClient(redisDb)
  
  return redisDb, redisJsonDb
  }
  </code></pre>
  <p>App.env file:</p>
  <pre><code> # Server
   SERVER_PORT=:8888
  
   # config
   DEVELOPMENT=true
  
   # Redis DB
   REDIS_DB_HOST=redis
   REDIS_DB_PORT=:6378
   REDIS_DB_PASSWORD=
   REDIS_DB_NAME=0#Default DB
  
   # PG DB
   PG_DB_HOST=postgres
   PG_DB_PORT=5432
   PG_DB_USER=postgres
   PG_DB_PASSWORD=38043
   PG_DB_NAME=postgres
  
   # Rabbitmq
   RABBITMQ_HOST=rabbitmq
   RABBITMQ_PORT=:5672
  </code></pre>
  <p>docker-compose.yaml (format is abit off here)</p>
  <pre><code>version: &quot;3.3&quot;
  services:
   postgres:
      container_name: student-grades
      image: postgres:latest
      environment:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: 38043
          POSTGRES_DB: postgres
      ports:
          - &quot;5432:5432&quot;
      volumes:
          - pgdata:/var/lib/postgresql/data
  
   redis:
     container_name: exam-db
     image: redis/redis-stack
     ports:
       - &quot;6378:6378&quot;
       - &quot;8001:8001&quot;
     volumes:
       - redisdata:/var/lib/redis/data
     restart: unless-stopped
  
    rabbitmq:
      image: rabbitmq:3-management
      container_name: RabbitMQ
      volumes:
         - rabbit-data:/data/rabbit
      ports:
        - &quot;5672:5672&quot;
        - &quot;15672:15672&quot;
      restart: unless-stopped
  
   exam-service:
      container_name: exam-service
      image: eyadzz/dexam_exam_service
      ports:
        - &quot;8888:8888&quot;
     depends_on:
        - &quot;postgres&quot;
     links:
        - &quot;postgres&quot;
  volumes:
    redisdata:
    pgdata:
    rabbit-data:
  </code></pre>
  <p>Error Message:</p>
  <blockquote>
  <p>2022/07/03 18:22:01.012088 driver.go:27: Can't connect with Redis database Errors: dial tcp 172.23.0.4:6378: connect: connection refused</p>
  </blockquote>
  <p>Can anyone spot the problem?</p>