I have Docker and Docker Compose on my machine and I have a docker-compose.yml file. Inside of this file I define two services like so
...
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
...
It is quite a big docker-compose.yml file, which also contains definitions of consul-server and registrator containers. At first glance, everything works good. When I run:
$ docker-compose up
I see that all my containers are running and I see no error messages. I can even check, that for example php container is indeed running (just going to localhost:8181, I see a nice html page rendered with this service). However, the problem is, this php service is not registered with Registrator. I check it like so:
$ curl 127.0.0.1:8500/v1/catalog/services
As a result, I get this:
{"consul-server-8500":[], "nginx-proxy-80":[]}
So, for some strange reason Registrator registered successfully nginx-proxy service, but skipped php service. I wonder why. I really need it, since based on this, I would create consul templates for nginx-proxy service. So, I need some help.
EDIT
This is how I define consul and registrator services:
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
And this is how my registrator Dockerfile looks like:
FROM gliderlabs/registrator:latest
ENV SERVICE_ID=registrator
ENV SERVICE_NAME=registrator
ENTRYPOINT ["/bin/registrator"]
Registrator log
Not sure, if it is important:
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
As far as I can see Registrator ignores my php service (docker id=74a190734619). But I do not know how can I fix it.
According to logs registrator registers only those ports which published to your host. And it make sense. Consul is service discovery tool and there is no sense to register services which has no published ports.
P.S. you can remove links from your docker-compose as you are using version 2 (links are deprecated and networks usage more preferable). It's not about your problem. Just advice.