webproject-xyz / docker-hostsfile-sync
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'
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 4
pkg:composer/webproject-xyz/docker-hostsfile-sync
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- ext-filter: *
- jane-php/open-api-runtime: ^7.10.3
- phpdocumentor/reflection-docblock: ^5.6.6
- phpstan/phpdoc-parser: ^2.3.1
- symfony/console: ^7.4.3 || ^8.0
- symfony/http-client: ^7.4.3 || ^8.0
- symfony/property-access: ^7.4.3 || ^8.0
- symfony/property-info: ^7.4.3 || ^8.0
- symfony/runtime: ^7.4.1 || ^8.0
- symfony/serializer: ^7.4.3 || ^8.0
- webproject-xyz/docker-api-client: ^1.3.0
Requires (Dev)
- codeception/codeception: ^5.3.3
- codeception/module-asserts: ^3.3.0
- codeception/module-phpbrowser: ^3.0.2
- friendsofphp/php-cs-fixer: 3.92.5
- jane-php/open-api-3: ^7.10.3
- roave/security-advisories: dev-latest
- symfony/var-dumper: 7.4.3
- dev-main
- 1.7.0
- 1.6.0
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-renovate/major-symfony
- dev-renovate/phpdocumentor-reflection-docblock-6.x
- dev-renovate/lock-file-maintenance
- dev-renovate/all-minor-patch
- dev-renovate/composer-latest
- dev-renovate/php
This package is auto-updated.
Last update: 2026-01-16 05:50:18 UTC
README
A PHP docker API client with a cli tool to sync your hosts file with running docker containers to add hostnames for every network (inspired by https://github.com/iamluc/docker-hostmanager)
Example
bin/docker-api --help # ## add --hosts_file=/etc/hosts and run with sudo to sync file OR see result in ./tmp-hosts if not # # use php 8.3 with symfony cli symfony php bin/docker-api synchronize-hosts -v --reverse-proxy-host-ip=172.16.238.100 # on php 8.3+ php bin/docker-api synchronize-hosts -v --reverse-proxy-host-ip=172.16.238.100
hosts file (/etc/hosts) sync
Docker Compose/Podman Compose
docker compose up -d
# see logs
docker compose logs -f
Docker/Podman
docker pull ghcr.io/webproject-xyz/docker-hosts-file-sync:latest
docker run -d --name docker-hostfile-sync --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /etc/hosts:/app/hosts ghcr.io/webproject-xyz/docker-hosts-file-sync:latest
# or with reverse-proxy-ip e.g. "172.16.238.100"
docker run -d --name docker-hostfile-sync --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /etc/hosts:/app/hosts ghcr.io/webproject-xyz/docker-hosts-file-sync:latest --reverse-proxy-host-ip=172.16.238.100
Example of hosts file
This is based on 2 containers
- container 1 (jwilder-proxy) has multiple aliases
- container 2 (actual_server) has multiple aliases, an alias with a "normal" url (actual.realFancyUrl.tld set on the proxyNet network)
[...your stuff]
## docker-hostsfile-sync
# container - reverse proxy
172.16.238.100 proxy.local
# container - default network
172.19.0.2 actual_server.docker actual_server.actual-server_default
# container - proxyNet network (reverse proxy net)
172.16.238.2 actual_server.proxyNet
# reverse proxy entry from container env var: DOMAIN_NAME (multiple possible with)
# and reverse proxy entry from container network alias (with dot like "actual.my-reverse-proxy-url.xyz")
172.16.238.100 actual.my-reverse-proxy-url.xyz dev-actual.my-reverse-proxy-url.xyz
## docker-hostsfile-sync-end