Automatic update /etc/hosts file on start/stop containers which defined `hostname` option.
50K+
Automatic update /etc/hosts on start/stop containers by labels.
Start up docker-hosts-updater:
$ docker run -d --restart=always \
--name docker-hosts-updater \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/hosts:/opt/hosts \
grachev/docker-hosts-updater
Start containers with label ru.grachevko.dhu option
% docker run -d --label ru.grachevko.dhu=nginx.local nginx
Try to ping from host
% ping nginx.local
You can add multiple hosts, just separate them by semicolon:
$ docker run --label ru.grachevko.dhu="nginx.local;nginx.ru" nginx
$ ping nginx.local
$ ping nginx.ru
Add subdomains by using pattern {www,api}.nginx.local:
$ docker run -d --label ru.grachevko.dhu="{www,api}.nginx.local" nginx
$ ping nginx.local
$ ping www.nginx.local
$ ping api.nginx.local
If you want to run two containers with same hosts and want one override another, just add priority after colon:
$ docker run -d --label ru.grachevko.dhu="nginx.local" nginx
$ docker run -d --label ru.grachevko.dhu="nginx.local:10" nginx
$ ping nginx.local
Container with greater priority will be used. Default priority 0. If priority is the same then early created container will be used.
In order to pass the traffic through the loadbalancer you should define container's name or valid IPv4. Just add one more colon and container name after it.
$ docker run -d --name lb nginx
$ docker run -d --label ru.grachevko.dhu="nginx1.local:0:lb" nginx
$ docker run -d --label ru.grachevko.dhu="nginx2.local:0:127.0.0.1" nginx
$ ping nginx1.local // ip of lb
$ ping nginx2.local // ip of lb
Keep in mind, loadbalancer container must have fixed name.
Content type
Image
Digest
Size
42.3 MB
Last updated
almost 7 years ago
docker pull grachev/docker-hosts-updater