It’s been a hot minute since I’ve worked on the Windows Hosts Writer (WHW) and based on some feedback, a few changes were made:
- Now, WHW will listen to ANY network by default. No more having to remember to set it to nat or docker_default. You can still specify an override through the environment variable as before.
- Ability to map IPs from a single container to multiples. For example, if you’re using Traefik for SSL, and you want to have your CM and CD instances go through that, instead of direct to the container, you can totally do that! Per Bering has a good example of how to do this in docker-compose: https://github.com/pbering/sitecore-docker-https-example . This makes things easier, though.
- Added Support for Windows 2004. Yeah, we’re that trendy here at Rock, Paper, Sitecore.
What’s this look like as part of a docker-compose file? Glad you asked!
hostswriter: image: rahnemann/windows-hosts-writer:2.0-nanoserver-1809 volumes: - C:\windows\system32\drivers\etc:C:\driversetc - type: npipe source: '\\.\pipe\docker_engine' target: '\\.\pipe\docker_engine' environment: TERMINATION_MAP: id,cm,cd:traefik
The above example, for Windows 1809, will listen to ALL networks, and any requests to id, cm, cd services will map to the traefik endpoint. Your hosts file would look like this:
172.26.134.249 e09c1b17b317 traefik #e09c1b17b317b89c0283678b27022b474e915f9b82896d066b532e26c5a597bb by whw 172.26.134.127 ccbbf93eca6d rendering #ccbbf93eca6dc7cf9ff73b984a376bfe312f14886e8e12db6885c9e7732dd533 by whw 172.26.134.249 faa3cac5385d cd basic-company-cd.sc.localhost #faa3cac5385d89f2fb437eed9e612e6b94f6504e1a1e2c53138d5ab24ed58987 by whw 172.26.134.249 1749cd323f73 cm basic-company-cm.sc.localhost #1749cd323f7376203f501ed2be00a814485f6a59d45fc161f31c10b07dd4e5d5 by whw 172.26.134.249 64943e3887a7 basic-company-id.sc.localhost id #64943e3887a7cc2cc569a5444ad740be519a45cc589a61369842c41e00eaf758 by whw 172.26.129.184 c49f190a65cb redis #c49f190a65cb2f31358c6926323dd4b7330f2a560f78f5d6d54bfd217de14299 by whw 172.26.143.192 c0b4c7e27b81 mssql #c0b4c7e27b816a3137ccbc2fe6c2432d45cb3de9185b9b403eb8ecf04fd5864e by whw 172.26.139.23 e38827c7a858 solr #e38827c7a858ea090ebe5e59df5ea618c69ea4a6d99784c639f7f4ec7994d757 by whw
Notice how the CD, CM, and ID hosts entries share the same IP as Traefik.
You can snag the latest version on Docker Hub here: https://hub.docker.com/r/rahnemann/windows-hosts-writer/ or view the GitHub page: https://github.com/RAhnemann/windows-hosts-writer
Edit: Version 2.0 has been released. Read more about it here!