consul
service integration for docker
containers
doko
uses container id as consul service id, use container labels for other service definitions.
go install -u go.guoyk.net/doko
doko.name
, name of the servicedoko.port
, port of the service, bothhost
mode and classicbridge
mode are supporteddoko.tags
, tags of the service, comma separateddoko.check
, check mode, onlyhttp
andgrpc
are supporteddoko.check.interval
, check interval, default10s
doko.check.timeout
, check timeout, default5s
doko.check.http.path
,http
mode only, the path of health check endpoint, default to_health
doko.meta.XXX
, meta of the service
-
Install and start
docker
-
Install and start
consul
consul agent -dev -ui
-
Install and run
doko
go install -u go.guoyk.net/doko doko
-
Start a container with specified labels
docker run -d --network host --name nginx1 \ --label doko.name=demo --label doko.port=80 nginx docker run -d -p 80 --name nginx2 \ --label doko.name=demo --label doko.port=80 nginx
You can also set label by
LABEL
command inDockerfile
-
Query
consul
by browsing Web UIhttp://127.0.0.1:8500
You will see a service with name
demo
and port80
is registered automatically -
Stop the container
docker stop nginx1 nginx2
-
Check
consul
Web UI againYou will see that service is unregistered automatically.
When label doko.check
is set to http
, doko
will register a http
health check to consul
http://127.0.0.1:[PORT]/_health
You can specify the path by label doko.check.http.path
When label doko.check
is set to grpc
, doko
will register a grpc
health check to consul
doko
will register self as a consul
service, the instance id will be persisted to current directory
doko-id
To deregister current doko instance, run doko --deregister
manually.
Guo Y.K., MIT License