Docker群和服务发现

我正在从docker组成文件转移到使用docker群,但我只是无法弄清楚这一点。

我有两个服务 – 一个nginx代理和一个网站,在docker swarm(有三个节点)

我得到的问题是我需要将nginxconfiguration为proxy_pass到后端网站。 目前,我能做到这一点的唯一方法是指定一个节点的IP地址。

我的服务创build如下:

docker service create --mount type=bind,source=/../nginx.conf,target=/etc/nginx/conf.d/default.conf \ -p 443:443 \ --name nginx \ nginx

docker service create --name ynab \ -p 5000:5000 \ --replicas 2 \ scottrobertson/fintech-to-ynab

我试过使用服务名称,但只是不起作用。

真的,我不认为我应该甚至暴露ynab服务端口(至less这将工作时,我用docker-compose)

在其中一个nginx容器中,我尝试了以下方法: root@5fabc5611264:/# curl http://ynab:5000/ping curl: (6) Could not resolve host: ynab root@5fabc5611264:/# curl http://nginx:5000/ping curl: (6) Could not resolve host: nginx root@5fabc5611264:/# curl http://127.0.0.1:5000/ping curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused root@5fabc5611264:/# curl http://localhost:5000/ping curl: (7) Failed to connect to localhost port 5000: Connection refused

使用进程列表我尝试连接到正在运行的实例ID,并且名称: root@5fabc5611264:/# curl http://ynab.1:5000/ping curl: (6) Could not resolve host: ynab.1 root@5fabc5611264:/# curl http://pj0ekc6i7n0v:5000/ping curl: (6) Could not resolve host: pj0ekc6i7n0v

但我只能得到它的工作,如果我使用节点的公共IP地址: root@5fabc5611264:/# curl http://192.168.1.52:5000/ping pong root@5fabc5611264:/# curl http://192.168.1.53:5000/ping pong root@5fabc5611264:/# curl http://192.168.1.51:5000/ping pong

我真的不希望使用公共IP,以防止节点故障。 我相信我一定是做错了!

这些服务需要连接到同一个networking才能工作。

 $ docker network create -d overlay fake-internet-points $ docker service create --name service_one --network fake-internet-points [...] $ docker service create --name service_two --network fake-internet-points [...]