我的机器上有Docker和Docker Compose,我有一个docker-compose.yml文件。在这个文件里面我定义了两个像这样的服务
...
nginx:
build:
context: ./nginx-proxy'
image: nginx-proxy
container_name: nginx
ports:
- 8181:80
links:
- consul-server
- php
depends_on:
-registrator
php:
build:
context: ./php-apache
image: php-apache
container_name: php-apache
depends_on:
- registrator
...
这是一个相当大的docker-compose.yml文件,它还包含consul-server和registrator容器的定义。乍一看,一切都很好。我跑的时候:
$ docker-compose up
我看到所有容器都在运行,我看不到任何错误消息。我甚至可以检查,例如php容器确实正在运行(只是去localhost:8181,我看到一个很好的html页面使用此服务呈现)。但问题是,这个php服务没有在Registrator注册。我这样检查:
$ curl 127.0.0.1:8500/v1/catalog/services
结果,我得到了这个:
{"consul-server-8500":[], "nginx-proxy-80":[]}
所以,由于一些奇怪的原因,Registrator注册成功的nginx-proxy服务,但跳过了php服务。我想知道为什么。我真的需要它,因为基于此,我将为nginx代理服务创建consul模板。所以,我需要一些帮助。
修改
这是我定义领事和registrator服务的方式:
version: '2'
services:
consul-server:
build:
context: ./consul-server
hostname: ${MYHOST}
ports:
- 8500:8500
registrator:
build:
context: ./registrator
container_name: registrator
command: "consul://${MYHOST}:8500"
hostname: ${MYHOST}
network_mode: host
depends_on:
- consul-server
volumes:
- /var/run/docker.sock:/tmp/docker.sock
这就是我的registrator Dockerfile的样子:
FROM gliderlabs/registrator:latest
ENV SERVICE_ID=registrator
ENV SERVICE_NAME=registrator
ENTRYPOINT ["/bin/registrator"]
Registrator log
不确定,如果重要的话:
2017/01/17 11:52:52 Starting registrator v7 ...
2017/01/17 11:52:52 Using consul adapter: consul://127.0.0.1:8500
2017/01/17 11:52:52 Connecting to backend (0/0)
2017/01/17 11:52:52 consul: current leader
2017/01/17 11:52:52 Listening for Docker events ...
2017/01/17 11:52:52 Syncing services on 2 containers
2017/01/17 11:52:52 ignored: c7251ebcbec4 no published ports
2017/01/17 11:52:52 ignored: d22263dca979 port 8301 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8302 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8600 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8600 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8300 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8302 not published on host
2017/01/17 11:52:52 ignored: d22263dca979 port 8301 not published on host
2017/01/17 11:52:52 added: d22263dca979 consul
2017/01/17 11:52:52 ignored: d22263dca979 port 8400 not published on host
2017/01/17 11:52:52 ignored: c7251ebcbec4 no published ports
2017/01/17 11:52:52 ignored: 74a190734619 port 80 not published on host
2017/01/17 11:52:53 added: bd9f65b332a5 nginx
2017/01/17 11:52:53 ignored: bd9f65b332a5 port 443 not published on host
据我所知,Registrator忽略了我的php服务(docker id = 74a190734619)。但我不知道如何解决它。
答案 0 :(得分:2)
根据日志registrator仅注册发布到您的主机的那些端口。这是有道理的。 Consul是服务发现工具,没有意义来注册没有发布端口的服务。
P.S。您可以在使用版本2时从docker-compose中删除链接(不建议使用链接,更可取更多网络使用)。这不是你的问题。只是建议。