add/update/rm all docker containers to /etc/hosts automatically.
1.4K
docker-etchosts is a script that monitors dockers event stream, and adds/updates/removes containers to your (/etc/)hosts-file on the fly. The script is based on dockermon by CyberInt.
Started without further parameters the script will connect to /var/run/docker.sock and modify hosts in the current working directory.
It will also process all currently running containers.
To connect to a remote docker node or swarm cluster use --socket-url, e.g.
python docker-etchosts.py --socket-url='tcp:///localhost:2335'
To specify the full path to your hosts file you would like modified pass --hosts-file=/etc/hosts.
To skip processing running containers on script startup pass --skip-running.
The script runs fine dockerized, the supplied Dockerfile creates a image of about 80 MB size, running consumes about 15 MB RAM.
docker build -t dockerhosts:pre .
docker run -v /etc/hosts:/hosts -v /var/run/docker.sock:/var/run/docker.sock --privileged dockerhosts:pre
docker run -v /etc/hosts:/hosts --privileged dockerhosts:pre --socket-url=tcp:///localhost:2335
...or instead of the above, just do:
docker-compose up -d
:)
Content type
Image
Digest
Size
27.6 MB
Last updated
almost 10 years ago
docker pull hnrd/docker-etchosts