我使用Windows docker工具箱,感到困惑。我想将redis指令程序(https://www.npmjs.com/package/redis-commander)与来自docker hub的docker image redis一起使用。
我从上面的链接中使用了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
现在我可以使用端口8081上的工具箱IP启动应用程序 它说未定义的Redis服务器:local:redis:6379:0
由于我使用的是工具箱,所以我假设我必须在撰写文件中输入正确的IP。
与$ docker run --name some-redis -d redis
一起使用redis
工作正常,我可以通过本地服务器访问服务器:6379
但是REDIS_HOSTS=local:redis:6379
是否有帮助正确设置此设置?
答案 0 :(得分:0)
我认为您错过了链接两个容器的链接。 redis容器需要端口+链接,redis-commander需要正确的环境。 您只能将容器名称用于链接/环境。
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
答案 1 :(得分:0)
要修复您需要像这样的链接 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
或者那个:
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: