sameersbn / docker-redis

Dockerfile to create a Docker container image for Redis.
MIT License
156 stars 139 forks source link

Cannot change port using docker compose #18

Closed nidkil closed 5 years ago

nidkil commented 5 years ago

Hi,

I have tried to change the port using the provided docker-compose.yml file, but this does not work.

This is the changed docker-compose.yml file:

version: '3.7'
services:
  redis:
    container_name: redis-basic
    hostname: redis
    image: sameersbn/redis:4.0.9-2
    ports:
      - "6380:6380"
    volumes:
      - type: volume
        source: redis-data
        target: /data
    restart: always
volumes:
  redis-data: {}

This is the node code I'm using to test it:

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 file and the code then it works.

Any ideas how to change the port?

nidkil commented 5 years ago

Never mind, my bad. should be:

version: '3.7'
services:
  redis:
    ports:
      - "6380:6379"
nidkil commented 5 years ago

The problem was not solved with the above change when used in conjunction with redis-commander. I needed to change the port Redis was running on as well set ut 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
    entrypoint: /sbin/entrypoint.sh -- --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: {}