Download the PHP package webproject-xyz/docker-hostsfile-sync without Composer
On this page you can find all versions of the php package webproject-xyz/docker-hostsfile-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webproject-xyz/docker-hostsfile-sync
More information about webproject-xyz/docker-hostsfile-sync
Files in webproject-xyz/docker-hostsfile-sync
Package docker-hostsfile-sync
Short Description A PHP docker API client with a cli tool to sync your hosts file with running docker containers to add hostnames for every network like '172.16.238.100 jwilder-proxy.docker jwilder-proxy.proxyNet jwilder.proxyNet proxy.local.proxyNet'
License MIT
Homepage https://www.webproject.xyz
Informations about the package docker-hostsfile-sync
Docker Hosts File Sync
Automatically sync your /etc/hosts file with running Docker containers. Each container gets hostnames for every network it's connected to.
Inspired by docker-hostmanager
Features
- Listens to Docker events in real-time (start, stop, restart)
- Generates hostnames based on container name and network
- Supports reverse proxy setups (nginx-proxy, Traefik, etc.)
- Reads hostnames from
DOMAIN_NAMEandVIRTUAL_HOSTenvironment variables - Works with Docker and Podman
Quick Start
Using Docker (Recommended)
Using Docker Compose
Configuration
Command Line Options
| Option | Short | Description | Default |
|---|---|---|---|
--hosts_file |
-f |
Path to hosts file | ./tmp-hosts |
--tld |
-t |
TLD suffix for hostnames | .docker |
--reverse-proxy-host-ip |
-r |
IP address of your reverse proxy | - |
Environment Variables
You can also configure via environment variables:
| Variable | Description |
|---|---|
HOSTS_FILE |
Path to hosts file |
TLD |
TLD suffix for hostnames |
Examples
Example 1: Basic Setup
A simple web application with a database:
Generated hosts entries:
Now you can access your services:
http://webapp.docker→ nginx containermysql -h database.docker→ MySQL container
Example 2: Multiple Networks
When containers are connected to multiple networks, each network gets its own hostname:
Generated hosts entries:
This allows:
- Frontend services reach
webappviawebapp.frontend - Backend services communicate via
*.backendhostnames - Your host machine can reach any container directly
Example 3: With Reverse Proxy (nginx-proxy)
For production-like setups with a reverse proxy, use the --reverse-proxy-host-ip option. This routes URL-like hostnames (containing dots) to your proxy:
Generated hosts entries:
Now you can:
- Access
http://webapp.local→ routed through nginx-proxy to webapp - Access
http://api.local→ routed through nginx-proxy to api - Access
http://webapp.proxy→ direct to webapp container (bypassing proxy) - Debug with
http://api.docker→ direct container access
Example 4: Network Aliases
Network aliases let you give containers additional hostnames. Aliases containing a dot (.) are treated as URLs and routed to the reverse proxy:
Generated hosts entries:
How It Works
The tool manages a section in your hosts file between these markers:
Everything outside these markers is left untouched.
Hostname Generation Rules
| Source | Example | Generated Hostname | Target IP |
|---|---|---|---|
| Container name | webapp |
webapp.networkname |
Container IP |
| Simple network alias | frontend |
frontend.networkname |
Container IP |
| URL-like network alias | app.example.com |
app.example.com |
Reverse proxy IP |
DOMAIN_NAME env var |
api.local |
api.local |
Reverse proxy IP |
VIRTUAL_HOST env var |
www.app.local |
www.app.local |
Reverse proxy IP |
URL-like aliases (containing a .) are assumed to be real domain names that should route through your reverse proxy. Simple aliases (no .) are combined with the network name.
Running Locally (Development)
Troubleshooting
Hosts file not updating
-
Check the container has write access to the hosts file:
- Check logs for errors:
Container not appearing in hosts file
Containers must be "exposed" (have at least one network with an IP address). Check your container:
License
MIT
All versions of docker-hostsfile-sync with dependencies
ext-filter Version *
jane-php/open-api-runtime Version ^7.14.0
phpstan/phpdoc-parser Version ^2.3.5
symfony/console Version ^8.1.6
symfony/http-client Version ^8.1.6
symfony/property-access Version ^8.1.4
symfony/property-info Version ^8.1.6
symfony/runtime Version ^8.1.0
symfony/serializer Version ^8.1.6
webproject-xyz/docker-api-client Version ^1.5.2