Open fudali113 opened 7 years ago
@fudali113 If you use managed network in rancher the problem is obvious. CNI doesn't publish ports as CNM, that is default networking framework for docker that's supported by registrator. My solution is to use these flags:
It would be great if you could give an example docker-compose.yml
for this. It's not clear from this page or the doco page how to use these two options.
@juliangamble Ok, I'm going to do it tommorow. But keep in mind, that it works only with managed network(rancher option) that is CNI network and works because rancher set this label. If you publish ports or you use docker networking, e.g. bridge, host and so on, it won't work.
UPD: I was wrong. It works with bridge/host net. But I'm not sure about ports exposed by user. But with internal ports(EXPOSE in docker container) it works fine.
@juliangamble This is docker-compose's registrator definition:
registrator:
image: gliderlabs/registrator:master
net: host
restart: unless-stopped
volumes:
- /var/run/docker.sock:/tmp/docker.sock
command:
- -internal
- -useIpFromLabel=io.rancher.container.ip
- -cleanup
- consul://localhost:8500
N.B. This feature works only with master branch(tag).
Interesting - this is what I had setup before you had posted (posting for the benefit of others that run across this):
registrator:
image: gliderlabs/registrator:master
restart: always
container_name: registrator
net: host
volumes:
- /var/run/docker.sock:/tmp/docker.sock
command:
- -internal
- -cleanup
- consul://0.0.0.0:8500
labels:
- io.rancher.scheduler.global=true
- io.rancher.container.network=false
- io.rancher.container.dns=true
Since I was running registrator in rancher.
Then I did a tweak on my container docker-compose.yml
to enable viewing of my ports for rancher network managed containers internally via registrator and externally mapped to a port I could use (my port range is restricted):
ports:
- "50888:80"
- "80:80"
Thanks for this. It didn't solve my problem. (Needing to run 16 containers with internal port 8080 (tomcat maven) across four hosts.) There weren't enough internal ports.
So I ended up writing my own rancher pull request to solve this issue: https://github.com/juliangamble/registrator/tree/rancher-metadata-link
Hope it works for you!
(Any code review feedback or assistance getting this through the pull request process would be much appreciated).
Server: Version: 17.03.0-ce API version: 1.26 (minimum version 1.12) Go version: go1.7.5 Git commit: 60ccb22 Built: Thu Feb 23 10:54:03 2017 OS/Arch: linux/amd64 Experimental: false
docker run -d \ --name=registrator \ --net=host \ --volume=/var/run/docker.sock:/tmp/docker.sock \ gliderlabs/registrator:latest \ consul://localhost:8500
2017/4/5 下午4:40:462017/04/05 08:40:46 ignored: 7420e027963b no published ports 2017/4/5 下午4:41:562017/04/05 08:41:56 ignored: 7420e027963b no published ports 2017/4/5 下午4:42:162017/04/05 08:42:16 ignored: 7420e027963b no published ports 2017/4/5 下午4:43:312017/04/05 08:43:31 ignored: 7420e027963b no published ports 2017/4/5 下午4:44:012017/04/05 08:44:01 ignored: 7420e027963b no published ports 2017/4/5 下午4:44:362017/04/05 08:44:36 ignored: 7420e027963b no published ports
I use the rancher(v1.5.1) to manage and run the container, but as long as it is rancher start container registrator cannot read into port, would you please tell me what the solution to this case?