Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/npalm/docker-discovery-agent
Discovery agent for docker exposed ports
https://github.com/npalm/docker-discovery-agent
Last synced: 28 days ago
JSON representation
Discovery agent for docker exposed ports
- Host: GitHub
- URL: https://github.com/npalm/docker-discovery-agent
- Owner: npalm
- License: mit
- Created: 2016-06-10T10:40:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T20:37:47.000Z (about 5 years ago)
- Last Synced: 2024-10-04T16:57:57.271Z (about 2 months ago)
- Language: Go
- Homepage: https://040code.github.io/2018/02/14/service-discovery/
- Size: 4.88 KB
- Stars: 10
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![project unmaintained](https://img.shields.io/badge/project-unmaintained-red.svg)
# Discovery agent for docker exposed ports
A simple in go written agent that exposes a minimal REST api so a container can find the exposed port for a container port. The agent is just a workaround for the problem mentioned in https://github.com/docker/docker/issues/3778
## Usages
Start the agent
```
docker run -p 5555:8080 -v /var/run/docker.sock:/var/run/docker.sock \
--name docker-discovery-agent npalm/docker-discovery-agent
```Test the agent
```
export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | \
grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
docker run -it -p 80 --add-host="dockerhost:$(DOCKERHOST)" --rm centos /bin/bash
```
Now you are on the shell of the container. You can look up the exposed port as follow.
```
# find the container id
CONTAINER_ID=$(cat /proc/self/cgroup | grep "cpu:/" | sed 's/\([0-9]\):cpu:\/docker\///g')# request the port binding for mapped port 80
curl "http://dockerhost:5555/container/${CONTAINER_ID}/portbinding?port=80&protocol=tcp"
```
The response will look like:
```[{"HostIp":"0.0.0.0","HostPort":"12345"}]```## REST API
Only a minimal API is implemented## Health check
Once the service is running the health check should response with a 200 status code.
```resource:
response: 200 OK
```## Port binding
```
resource: /container/{id}/portbinding?port={port}&protocol={protocol}
response: A JSON resprenting the exposded port for container with id
{
"HostIp": "",
"HostPort": ""
}
```