我正在使用Ansible docker module设置Redis服务(请参阅下面的ansible角色)
- hosts: redis
roles:
- role: angstwad.docker_ubuntu
sudo: true
tasks:
- name: data container
sudo: true
docker:
name: redis-data
image: busybox
state: started
volumes:
- /data/redis
- name: redis container
sudo: true
docker:
name: redis-service
image: redis:3
command: redis-server --appendonly yes
state: started
expose: 6379
volumes_from:
- redis-data
配置完成后,redis-service
容器已启动,但当我尝试使用redis-cli
连接到redis时出现以下错误:
vagrant@dev1:~$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
注意:redis-service
似乎正常运行:
vagrant@dev1:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e8f27b14479 redis:3 "/entrypoint.sh redis" 12 minutes ago Up 12 minutes 6379/tcp redis-service
vagrant@dev1:~$ docker logs 3e8f27b14479
...
1:M 02 Sep 15:41:16.532 * The server is now ready to accept connections on port 6379
你知道可能导致问题的原因吗?
答案 0 :(得分:3)
我终于找到了问题:端口属性也必须设置(不仅公开)
- hosts: redis
roles:
- role: angstwad.docker_ubuntu
sudo: true
tasks:
- name: data container
sudo: true
docker:
name: redis-data
image: busybox
state: started
volumes:
- /data/redis
- name: redis container
sudo: true
docker:
name: redis-service
image: redis:3
command: redis-server --appendonly yes
state: started
expose: 6379
ports:
- 6379:6379
volumes_from:
- redis-data