Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Redis port in Docker Compose not working

I have a Docker Compose file that starts two services: Redis and Redis Commander. Using the default Redis port 6379 works fine. After changing the Redis port to 6380 Redis Commander cannot connect to Redis anymore.

Error:

setUpConnection Redis error Error: connect ECONNREFUSED 172.19.0.2:6380

This is the docker-compose.yml file:

version: '3.7'
services:
  redis:
    container_name: redis
    hostname: redis
    image: sameersbn/redis:4.0.9-2
    ports:
      - "6380:6379"
    expose:
      - "6380"
    volumes:
      - type: volume
        source: redis-data
        target: /data
    restart: always
  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    restart: always
    environment:
      - REDIS_HOSTS=local:redis:6380
    ports:
      - "8082:8081"
volumes:
  redis-data: {}

I can connect to Redis on port 6380 using the following Node code:

import redis from 'redis'

const config = {
  host: '127.0.0.1',
  port: 6380,
  no_ready_check: true
}

const client = redis.createClient(config.port, config.host)

client.set('expireName', 'nidkil', (err, reply) => {
  if (err) {
    console.error('Error occurred:', err)
  } else {
    console.log('Response:', reply)
  }
})

If I change the port back to 6379 in the docker-compose.yml then Redis Commander can connect.

Any suggestions how I can make Redis Commander connect to Redis on port 6380?

like image 402
nidkil Avatar asked May 14 '19 17:05

nidkil


People also ask

Does Docker compose expose ports?

Docker Compose exposes all specified container ports, making them reachable internally and externally from the local machine. Once again, in the PORTS column, we can find all the exposed ports. The value to the left of the arrow shows the host address where we can reach the container externally.

What is Redis default port?

By default, the Redis server runs on TCP Port 6379.


2 Answers

The answer of @Mihai helpt me figure out the solution. I needed to change the port Redis is running on as well as the exposed port. This is the working Docker compose file.

version: '3.7'
services:
  redis:
    container_name: redis
    hostname: redis
    image: sameersbn/redis:4.0.9-2
    command: --port 6380
    ports:
      - "6380:6380"
    expose:
      - "6380"
    volumes:
      - type: volume
        source: redis-data
        target: /data
    restart: always
  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    restart: always
    environment:
      - REDIS_HOSTS=local:redis:6380
    ports:
      - "8082:8081"
volumes:
  redis-data: {}
like image 104
nidkil Avatar answered Nov 16 '22 21:11

nidkil


You changed the exposed port on the host. You did not change the internal port in the container. Your redis instance continues to run on the default port (6379).

Also this statement expose: - "6380" can be omitted since it is not useful.

like image 35
Mihai Avatar answered Nov 16 '22 23:11

Mihai