{"id":22403360,"url":"https://github.com/springload/set-alias-on-host","last_synced_at":"2025-10-12T04:15:19.119Z","repository":{"id":66138719,"uuid":"155038082","full_name":"springload/set-alias-on-host","owner":"springload","description":"Pure bash script to set docker network alias on host machine","archived":false,"fork":false,"pushed_at":"2019-01-18T00:18:36.000Z","size":14,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-27T00:54:37.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/springload.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":"2018-10-28T05:20:20.000Z","updated_at":"2022-06-21T03:03:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"f969ea99-8a07-4c73-9870-4da204f319b1","html_url":"https://github.com/springload/set-alias-on-host","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/springload/set-alias-on-host","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springload%2Fset-alias-on-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springload%2Fset-alias-on-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springload%2Fset-alias-on-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springload%2Fset-alias-on-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/springload","download_url":"https://codeload.github.com/springload/set-alias-on-host/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springload%2Fset-alias-on-host/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010259,"owners_count":26084718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-12-05T09:16:55.567Z","updated_at":"2025-10-12T04:15:19.070Z","avatar_url":"https://github.com/springload.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# set-alias-on-host\n`set-alias-on-host.sh` is a shell script to set docker network alias on host machine by overwriting \nhost `/etc/hosts` file. It enables domain name resolved on host machine to point to docker container IP. \nIntention of `set-alias-on-host.sh` is to help local development without overhead of configuring host DNS subsystem.\n\n### !!! Script is not intended to be used on production in any way !!!\n\n`set-alias-on-host.sh` implemented in a way it shall work as a docker-compose entrypoint (optional)\n\nBetter use however is as a command before actual web server application command.\nSo if you run the same service container with some service commands (that doesn't run web server) the \nscript will register IP address of the web server container only\n\n## Usage\n\n### !!! Create a backup of your hosts file before you let this script to play with it !!!\n\nScript usage\n```\nset-alias-on-host.sh /path/to/host/machine/etc/hosts/file www.test.domain optimal-command-to-start-after\n```\n\n### Docker setup\n\nAdd script to your docker image \n\nDockerfile example\n```\nADD https://raw.githubusercontent.com/springload/set-alias-on-host/master/set-alias-on-host.sh /usr/local/bin/\nRUN chmod +x /usr/local/bin/set-alias-on-host.sh\n```\n\n#### Option 1:\n\ndocker-compose example within the same container as your service\n```\nweb:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    networks:\n      fronend:\n        aliases:\n          - www.web.test  # define alias on docker network\n    volumes:\n      - \"/etc/hosts:/host/etc/hosts\"  # for linux based host\n      - \"/private/etc/hosts:/host/etc/hosts\" # for macOS based host\n    # run script first, then your specific web server app\n    command: [\"set-alias-on-host.sh\", \"/host/etc/hosts\", \"www.web.test\", \"nginx\", \"-g\", \"daemon off;\"]\n```\n\n#### Option 2:\n\ncreate service to run set-alias-on-host script for all services of interest\n\nfull docker-compose example\n```\nversion: '3.7'\n\nservices:\n  set_host_alias:\n    image: springload/set-alias-on-host\n    volumes:\n      - \"/etc/hosts:/host/etc/hosts\"\n    environment:\n      HOST_ALIAS: \"db.web.test www.web.test\"  # separate aliases by space or comma\n    depends_on:\n      - database   # database has to be running to find IP for db.web.test\n      - webserver  # webserver has to be running to find IP for www.web.test\n    networks:\n      web:\n        # container has to have access to proper network\n      \n  database:\n    image: postgres\n    volumes:\n      - \"./database/initial-scripts:/docker-entrypoint-initdb.d/:ro\"\n    environment:\n      POSTGRES_DB \"user\"\n      POSTGRES_USER \"postgres\"\n      POSTGRES_PASSWORD \"public-secret\"\n    networks:\n      web:\n        aliases:\n          - db.web.test  # set service alias \n          \n  webserver:\n    build:\n      context: .  \n      dockerfile: Dockerfile\n    depends_on:\n      - database\n    networks:\n      web:\n        aliases:\n          - www.web.test  # set service alias\n\nnetworks:\n  web:\n    # define network to be able to set host aliases\n\n```\n\n\u003e On MacOs you may need to allow a group write permission for `/private/etc/hosts` file\n\nStart your project with `docker-compose up` and you should see message similar to \n\u003e www.web.test entry added to hosts file\n\nCheck your system `hosts` file for new entry for `www.web.test` domain\nAccess your service wia `www.web.test` domain in your local browser","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringload%2Fset-alias-on-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringload%2Fset-alias-on-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringload%2Fset-alias-on-host/lists"}