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
?
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.
By default, the Redis server runs on TCP Port 6379.
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: {}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With