{"id":18426934,"url":"https://github.com/rimelek/hosts-gen-for-docker","last_synced_at":"2026-04-24T12:33:42.867Z","repository":{"id":87428407,"uuid":"103755509","full_name":"rimelek/hosts-gen-for-docker","owner":"rimelek","description":"Automatic hosts file generator for Docker containers","archived":false,"fork":false,"pushed_at":"2017-09-16T18:11:58.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T19:50:22.416Z","etag":null,"topics":["docker","docker-image","hosts","hostsfile"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rimelek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-16T13:51:42.000Z","updated_at":"2023-03-26T12:18:22.000Z","dependencies_parsed_at":"2023-12-01T01:15:11.326Z","dependency_job_id":null,"html_url":"https://github.com/rimelek/hosts-gen-for-docker","commit_stats":null,"previous_names":["rimelek/hosts-gen-for-docker"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rimelek/hosts-gen-for-docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rimelek%2Fhosts-gen-for-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rimelek%2Fhosts-gen-for-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rimelek%2Fhosts-gen-for-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rimelek%2Fhosts-gen-for-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rimelek","download_url":"https://codeload.github.com/rimelek/hosts-gen-for-docker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rimelek%2Fhosts-gen-for-docker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32224139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T10:26:35.452Z","status":"ssl_error","status_checked_at":"2026-04-24T10:25:27.643Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-image","hosts","hostsfile"],"created_at":"2024-11-06T05:09:11.027Z","updated_at":"2026-04-24T12:33:42.851Z","avatar_url":"https://github.com/rimelek.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description\n\nWhen you run web servers or other services inside Docker containers on your local machine, you may need domains to access them.\nIn that case you probably forward ports from the host machine to the containers or use a reverse proxy to made it easier, then edit /etc/hosts manually, unless you forget it. \n\nThis image based on the great [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen). Using it you can generate a list of IP addresses and host names, which can be used to update your local machine's hosts file by [itsziget/hosts-updater](https://hub.docker.com/r/itsziget/hosts-updater/) \n\nYou can decide per container whether the hosts belong to a specific container (reverse proxy for example) or the container where the hosts are defined.\n\n- Before you start the updater, make sure you have backup for /etc/hosts that won't be touched any container.\n- The next step is creating a hosts template. Copy the original hosts file as /etc/hosts.docker.tpl.   \n\nHere is an example Docker Compose file without reverse proxy:\n\n    version: \"2\"\n    \n    volumes:\n      hosts:\n    \n    services:\n      hosts-updater:\n        image: itsziget/hosts-updater\n        container_name: hosts-updater\n        volumes:\n          - /etc/hosts:/hosts/orig\n          - /etc/hosts.docker.tpl:/hosts/tpl:ro\n          - hosts:/hosts\n      hosts-gen:\n        image: itsziget/hosts-gen\n        container_name: hosts-gen\n        volumes:\n          - /var/run/docker.sock:/tmp/docker.sock:ro\n          - hosts:/hosts\n        environment:\n          UPDATER_CONTAINER: hosts-updater\n          \nThe environment variable UPDATER_CONTAINER contains the real name of the container and not service name.\nNow you have a working updater and you can run your application:\n\n    version: \"2\"\n    \n    services:\n      httpd:\n        image: httpd:2.4\n        environment:\n          VIRTUAL_HOST: my.first.domain.local,my.second.domain.local\n          \nThe environment variable VIRTUAL_HOST can contain multiple domains separated by commas\n\nLet's see how the application's compose file looks like when you forward the ports from your host machine to the container and want to use local IP addresses.\n\n    version: \"2\"\n    \n    services:\n      httpd:\n        image: httpd:2.4\n        environment:\n          VIRTUAL_HOST: my.first.domain.local,my.second.domain.local\n        ports:\n          - \"80:80\"\n        labels:\n          hosts.updater.target: 127.0.0.1\n          \nWhen you have a reverse proxy and you need the hosts to point the ip address of the proxy container, you need to add a label to the proxy container and refer this label in your application's compose file:\n\n    version: \"2\"\n    \n    services:\n      proxy:\n        image: nginx:1:10\n        labels:\n          - hosts.updater.proxy\n    # ...   \n    \nThe above code is just an incomplete proxy definition example. See application's definition below:\n\n    version: \"2\"\n    \n    services:\n      httpd:\n        image: httpd:2.4\n        environment:\n          VIRTUAL_HOST: my.first.domain.local,my.second.domain.local\n        labels:\n          hosts.updater.target: label:hosts.updater.proxy\n          \nNote that when you refer to the target container by label, the prefix \"label:\" must be used.\nThe name of the label after the prefix is optional. It just must be the same as the label you added to the proxy.\n\nNow I have to call your attention again to make backup for the original hosts file. I have never experienced any issue yet but always expect the unexpected! ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frimelek%2Fhosts-gen-for-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frimelek%2Fhosts-gen-for-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frimelek%2Fhosts-gen-for-docker/lists"}