docker-compose redis and redis commander

Viewed 5609

I use the windows docker toolbox and I am confused what I am missing. I want to use redis commander (https://www.npmjs.com/package/redis-commander) with a docker image redis from the docker hub.

I used the docker-compose.yml from above link:

version: '3'
services:
  redis:
    container_name: redis
    hostname: redis
    image: redis

  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    build: .
    restart: always
    environment:
    - REDIS_HOSTS=local:redis:6379
    ports:
    - 8081:8081

Now I can start the app with the toolbox IP on port 8081 Ther it says undefined redis server: local:redis:6379:0

Since I am using the toolbox I assume I have to put some IP correct in the compose file.

Using redis alone with $ docker run --name some-redis -d redis

works and I can reach the server und er local:6379

But what means REDIS_HOSTS=local:redis:6379

Any help to set this up correctly?

3 Answers

i think you missed to link your 2 containers. the redis container needs a port + link and the redis-commander the correct environment. you can only use the container name for the link/environment.

version: '3'
services:
  redis:
    container_name: redis
    hostname: redis
    image: redis
    ports
        - 6379:6379
    links: redis-commander

  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    build: .
    restart: always
    environment:
        - REDIS_HOSTS=redis
    ports:
        - 8081:8081

For fix that you need link redis and redis-commander like that:

version: "3.9"

services:
  redis:
    image: redis:6.2.5
    command: redis-server --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis:/var/lib/redis
      - redis-config:/usr/local/etc/redis/redis.conf
    ports:
      - ${REDIS_PORT}:6379
    networks:
      - redis-network

  redis-commander:
    image: rediscommander/redis-commander:latest
    restart: always
    environment:
      REDIS_HOSTS: redis
      REDIS_HOST: redis
      REDIS_PORT: redis:6379
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      HTTP_USER: root
      HTTP_PASSWORD: root
    ports:
      - 8081:8081
    networks:
      - redis-network

volumes:
  redis:
  redis-config:

networks:
  redis-network:
    driver: bridge

or that:

version: "3.9"

services:
  redis:
    image: redis:6.2.5
    command: redis-server --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis:/var/lib/redis
      - redis-config:/usr/local/etc/redis/redis.conf
    ports:
      - ${REDIS_PORT}:6379
    links:
      - redis-commander

  redis-commander:
    image: rediscommander/redis-commander:latest
    restart: always
    environment:
      REDIS_HOSTS: redis
      REDIS_HOST: redis
      REDIS_PORT: redis:6379
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      HTTP_USER: root
      HTTP_PASSWORD: root
    ports:
      - 8081:8081

volumes:
  redis:
  redis-config:

REDIS_HOSTS=local:redis:6379 means it will create config file to connect to docker container with the hostname redis on port 6379 and will have the connection name or label as local.

REDIS_HOSTS is used when you want to have multiple connection, separated by comma. There are some ways to write REDIS_HOSTS as mentioned in the documentation.

hostname

label:hostname

label:hostname:port

label:hostname:port:dbIndex

label:hostname:port:dbIndex:password

Example: Let say you want to use redis for two app called app1 and app2. app1 will have the db index 1, app2 will have the db index 2. The REDIS_HOSTS would look like:

REDIS_HOSTS=app1:redis:6379:1,app2:redis:6379:2

The working docker-compose.yml you could use (add network):

version: '3'
services:
  redis:
    container_name: redis
    hostname: redis
    image: redis
    networks:
      - redis_network

  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    build: .
    restart: always
    environment:
    - REDIS_HOSTS=local:redis:6379
    ports:
    - 8081:8081
    networks:
      - redis_network
networks:
  redis_network:
    driver: bridge

Related