manage /etc/hosts for docker containers.
Find a file
2016-09-05 10:09:40 +02:00
.gitignore initial commit 2016-09-04 18:49:50 +02:00
docker-compose.yml initial commit 2016-09-04 18:49:50 +02:00
docker-etchosts.py initial commit 2016-09-04 18:49:50 +02:00
Dockerfile initial commit 2016-09-04 18:49:50 +02:00
README.md fix a typo in README. 2016-09-05 10:09:40 +02:00

Automatically add/update/remove containers from hosts-file

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.

Usage

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.

Running in a container

The script runs fine dockerized, the supplied Dockerfile creates a image of about 80 MB size, running consumes about 15 MB RAM.

build

docker build -t dockerhosts:pre .

run

docker run -v /etc/hosts:/hosts -v /var/run/docker.sock:/var/run/docker.sock --privileged dockerhosts:pre

run and use tcp socket

docker run -v /etc/hosts:/hosts --privileged dockerhosts:pre --socket-url=tcp:///localhost:2335

docker-compose

...or instead of the above, just do:

docker-compose up -d

:)