|
|
||
|---|---|---|
| tests | ||
| .gitignore | ||
| dehu.py | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| requirements.txt | ||
DehU
Docker /etc/hosts Updater is a project made for populating your /etc/hosts file with aliases of current running Docker containers.
Installation
Go to this directory, activate your venv and then type:
pip install .
Usage
To populate your /etc/hosts file, run (as root):
dehu populate
A new section starting with ### Start of DehU entries and ending with ### End of DehU entries will be added to your /etc/hosts file.
You can ask DehU to print the content of the /etc/hosts file afterwards with the -v option.
To cleanup your /etc/hosts file, run (as root):
dehu clear
Examples
The compose.yml file in the tests directory contains a simple container architecture with:
-
A first container with the aliases:
-
A second container with the aliases:
You can start those containers by running:
cd tests
docker compose up -d
Then, run dehu to populate your /etc/hosts file
sudo dehu populate
You should have an output like this:
The following aliases have been ignored as they are shared by multiple containers:
- alias2.local
This alias being shared by two containers, it is ignored by dehu.
Moreover, your /etc/hosts file now contains this section:
### Start of DehU entries
tests-service_2-1 172.18.0.2
service_2 172.18.0.2
alias3.local 172.18.0.2
tests-service_1-1 172.19.0.2
service_1 172.19.0.2
alias1.local 172.19.0.2
### End of DehU entries
Where you can find the aliases manually set in the compose.yml file as well as
the aliases Docker compose automatically creates.
Now if you stop a container and rerun DehU:
docker compose down service_2
sudo dehu populate
You now have the following section in /etc/hosts:
### Start of DehU entries
tests-service_1-1 172.19.0.2
service_1 172.19.0.2
alias1.local 172.19.0.2
alias2.local 172.19.0.2
### End of DehU entries
Since there are no more conflicts, you find the alias2.local alias.
Finally, you can clear your /etc/hosts file by running:
sudo dehu clear