简体   繁体   English

docker-compose redis 和 redis 指挥官

[英]docker-compose redis and redis commander

I use the windows docker toolbox and I am confused what I am missing.我使用 windows docker 工具箱,我很困惑我缺少什么。 I want to use redis commander ( https://www.npmjs.com/package/redis-commander ) with a docker image redis from the docker hub.我想将 redis 指挥官( https://www.npmjs.com/package/redis-commander )与来自 d​​ocker hub 的 docker 镜像 redis 一起使用。

I used the docker-compose.yml from above link:我使用了上面链接中的 docker-compose.yml:

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现在我可以使用端口 8081 上的工具箱 IP 启动应用程序,它显示 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.由于我使用的是工具箱,我假设我必须在撰写文件中输入一些正确的 IP。

Using redis alone with $ docker run --name some-redis -d redis单独使用 redis 和$ docker run --name some-redis -d redis

works and I can reach the server und er local:6379工作,我可以在本地访问服务器:6379

But what means REDIS_HOSTS=local:redis:6379但是REDIS_HOSTS=local:redis:6379是什么意思

Any help to set this up correctly?有什么帮助可以正确设置吗?

For fix that you need link redis and redis-commander like that:要修复您需要这样的链接 redis 和 redis-commander:

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:

i think you missed to link your 2 containers. 我认为您错过了链接您的2个容器。 the redis container needs a port + link and the redis-commander the correct environment. redis容器需要端口+链接,redis-commander需要正确的环境。 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

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=local:redis:6379意味着它将创建配置文件以在端口6379上使用主机名redis连接到 docker 容器,并且连接名称标签local

REDIS_HOSTS is used when you want to have multiple connection, separated by comma. REDIS_HOSTS用于多个连接,以逗号分隔。 There are some ways to write REDIS_HOSTS as mentioned in the documentation .文档中所述,有一些编写REDIS_HOSTS的方法。

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 .示例:假设您想将 redis 用于两个名为app1app2的应用程序。 app1 will have the db index 1, app2 will have the db index 2. The REDIS_HOSTS would look like: app1的数据库索引为 1, app2的数据库索引为 2。 REDIS_HOSTS如下所示:

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

The working docker-compose.yml you could use (add network):您可以使用的工作 docker-compose.yml(添加网络):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM