Docker /etc/hosts Updater
Find a file
Charly Collin 4b852af516
fix: linting
feat: update gitignore
2025-06-17 08:38:42 +02:00
tests feat: add demo compose.yml file 2024-11-24 16:51:49 +01:00
.gitignore fix: linting 2025-06-17 08:38:42 +02:00
dehu.py fix: linting 2025-06-17 08:38:42 +02:00
LICENSE feat: First version of DehU 2024-11-24 16:24:17 +01:00
pyproject.toml feat: add list command to list aliases 2024-11-26 11:37:25 +01:00
README.md build: move to pyproject.toml project management 2024-11-26 11:17:01 +01:00
requirements.txt feat: First version of DehU 2024-11-24 16:24:17 +01:00

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:

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