docs: Update README for Docker Hoster
Improved project description, quick start, and container registration details.
This commit is contained in:
parent
8eed9f9e13
commit
d91e2e2676
61
README.md
61
README.md
|
|
@ -1,30 +1,65 @@
|
|||
# Hoster
|
||||
# Docker Hoster
|
||||
|
||||
A simple "etc/hosts" file injection tool to resolve names of local Docker containers on the host.
|
||||
A lightweight tool for dynamically injecting DNS entries into the host's `/etc/hosts` file to resolve names of local Docker containers.
|
||||
|
||||
hoster is intended to run in a Docker container:
|
||||
Docker Hoster runs as a Docker container itself, monitoring Docker events to automatically add or remove host entries for running containers. This enables seamless name resolution without manual configuration.
|
||||
|
||||
docker run -d \
|
||||
## Quick Start
|
||||
|
||||
Run Docker Hoster with the following command:
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name docker-hoster \
|
||||
-v /var/run/docker.sock:/tmp/docker.sock \
|
||||
-v /etc/hosts:/tmp/hosts \
|
||||
ghcr.io/mrmohebi/docker-hoster:latest
|
||||
```
|
||||
|
||||
The `docker.sock` is mounted to allow hoster to listen for Docker events and automatically register containers IP.
|
||||
- The `/var/run/docker.sock` volume allows Hoster to access Docker events and container metadata.
|
||||
- The `/etc/hosts` volume (mounted to `/tmp/hosts` inside the container) enables Hoster to update the host's DNS resolution file.
|
||||
|
||||
Hoster inserts into the host's `/etc/hosts` file an entry per running container and keeps the file updated with any started/stoped container.
|
||||
Hoster will insert one entry per container IP, updating the file in real-time as containers start, stop, or are renamed.
|
||||
|
||||
## How It Works
|
||||
|
||||
- **Event Listening**: Hoster connects to the Docker daemon via the socket and listens for container events (e.g., start, stop, die, destroy, rename).
|
||||
- **Hosts File Management**: Entries are added in a dedicated section of `/etc/hosts` (marked by `#-----------Docker-Hoster-Domains----------` and `#-----Do-not-add-hosts-after-this-line-----`). This section is safely updated or cleared without affecting other content.
|
||||
- **Supported Docker Versions**: Compatible with recent Docker releases (tested up to Docker 29).
|
||||
- **Built With**: Python 3.14 and the Docker SDK.
|
||||
|
||||
## Container Registration
|
||||
|
||||
Hoster provides by default the entries `<container name>, <hostname>, <container id>` for each container and the aliases for each network. Containers are automatically registered when they start, and removed when they die.
|
||||
By default, Hoster registers the following domains for each container:
|
||||
- Container name (e.g., `--name mycontainer`)
|
||||
- Hostname (e.g., `--hostname myhostname` or with domain if specified)
|
||||
- Container ID (shortened)
|
||||
- Network aliases (e.g., `--network-alias myserver.com`)
|
||||
|
||||
For example, the following container would be available via DNS as `myname`, `myhostname`, `et54rfgt567` and `myserver.com`:
|
||||
For example, running:
|
||||
|
||||
docker run -d \
|
||||
--name myname \
|
||||
```bash
|
||||
docker run -d \
|
||||
--name mycontainer \
|
||||
--hostname myhostname \
|
||||
--network somenetwork --network-alias "myserver.com" \
|
||||
mycontainer
|
||||
alpine
|
||||
```
|
||||
|
||||
If you need more features like **systemd interation** and **dns forwarding** please check [resolvable](https://hub.docker.com/r/mgood/resolvable/)
|
||||
Would make the container resolvable as `mycontainer`, `myhostname`, its ID (e.g., `abc123def456`), and `myserver.com`.
|
||||
|
||||
Any contribution is, of course, welcome. :)
|
||||
### Custom Domains via Labels
|
||||
Add extra domains using the `hoster.domains` label with comma-separated values:
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name mycontainer \
|
||||
-l hoster.domains="example.com,api.example.com" \
|
||||
alpine
|
||||
```
|
||||
|
||||
These will be appended to all default domains for broader resolution.
|
||||
|
||||
|
||||
## Contributions
|
||||
Contributions are welcome! Feel free to submit issues or pull requests on the [GitHub repository](https://github.com/MrMohebi/docker-hoster). The project includes GitHub Actions for automated image builds and publishing to GHCR on releases.
|
||||
Loading…
Reference in New Issue