Docker撰写:无法连接到Redis
我在这里https://docs.docker.com/get-started/part5/#recap-optional下面的Docker Compose教程
version: "3" services: web: image: example/get-started:part-1 deploy: replicas: 10 resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "80:80" networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - "8080:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: - webnet redis: image: redis ports: - "6379:6379" volumes: - ./data:/data deploy: placement: constraints: [node.role == manager] networks: - webnet driver: build: . links: - redis networks: webnet:
而Redis似乎在myvm1上运行,应用程序无法连接到它,并给出错误。
这是重要的应用程序代码:
from flask import Flask from redis import Redis, RedisError import os import socket redis = Redis(host="redis", db=0, socket_connect_timeout=0, socket_timeout=0) app = Flask(__name__) @app.route("/") def hello(): try: visits = redis.incr("counter") except RedisError: visits = "<i>cannot connect to redis. Counter disabled</i>" html = "<h3>Hello {name}!</h3>" \ "<b>Hostname:</b> {hostname}<br/>" \ "<b>Visits:</b> {visits}" return html.format(name=os.getenv("NAME", "World"), hostname=socket.gethostname(), visits=visits) if __name__ == "__main__": app.run(host='0.0.0.0', port=80)
VM IP:
myvm1 – virtualbox运行tcp://192.168.99.101:2376
v17.07.0策myvm2 – virtualbox运行tcp://192.168.99.102:2376
v17.07.0策
Redis在虚拟机上运行没有错误。
任何想法? 网上有很多类似的讨论,但都没有帮助。
如果redis在虚拟机上运行,绑定可能不正确。 你可以请检查它的绑定是否在0.0.0.0或者你需要编辑redisconfiguration绑定到0.0.0.0和端口的外部服务连接到它
- 将Postgresql数据库还原到Docker容器中,以便在Postgres启动时使用数据库
- Docker中的Clickhouse选项是experimental_allow_extended_storage_definition_syntax
- Docker私人信任的registry
- Docker安装debian openjdk-7-jre
- Docker工具箱代理configuration,Windows 7
- 在Docker中运行的Python / Flask中运行Vision API演示时的StatusCode.UNAUTHENTICATED
- 如何指定例如Ubuntu容器的特定版本?
- 有没有一种方法来否定.dockerignore中的模式?
- Docker拉Python