container-hosts extracts host names from containers and combines them with an ip address.
Reduce the management effort required for name resolution when adding or removing containers.
- Extraction of the host of a traefik router
- Extraction of host names via a self defined label (container-hosts / no traefik needed)
- Create and update a linux hosts file
- Extraction of container name to use it as host name
This example uses the container-hosts extractor to create a hosts file:
---
services:
container-hosts:
build: .
container_name: container-hosts
environment:
- TZ=Europe/Berlin
- HOST_IP4=192.168.178.2
- HOST_IP6=fd00::94c6:91aa:9ced
- EXTRACTOR=ContainerHosts
restart: unless-stopped
volumes:
- data:/data
- /var/run/docker.sock:/var/run/docker.sock:ro
busybox:
image: busybox
command: sleep 30
container_name: busybox
labels:
- container-hosts.enable=true
- container-hosts=busybox
version: '3.5'
volumes:
data: null
...
Result:
cat /data/hosts
192.168.178.2 busybox
fd00::94c6:91aa:9ced busybox
- blocky as Hosts file
- dnsmasq as addn-hosts