diff --git a/README.md b/README.md index 232e5c7..69159ab 100644 --- a/README.md +++ b/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 \ - -v /var/run/docker.sock:/tmp/docker.sock \ - -v /etc/hosts:/tmp/hosts \ - ghcr.io/mrmohebi/docker-hoster:latest +## Quick Start -The `docker.sock` is mounted to allow hoster to listen for Docker events and automatically register containers IP. +Run Docker Hoster with the following command: -Hoster inserts into the host's `/etc/hosts` file an entry per running container and keeps the file updated with any started/stoped container. +```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 `/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 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 `, , ` 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 \ - --hostname myhostname \ - --network somenetwork --network-alias "myserver.com" \ - mycontainer +```bash +docker run -d \ + --name mycontainer \ + --hostname myhostname \ + --network somenetwork --network-alias "myserver.com" \ + 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. \ No newline at end of file