{"id":21065831,"url":"https://github.com/washira/docker-compose-and-nginx","last_synced_at":"2026-04-09T08:54:47.055Z","repository":{"id":194337111,"uuid":"690616170","full_name":"Washira/docker-compose-and-nginx","owner":"Washira","description":"Demonstration of Reverse Proxy and Load Balancer using NGINX while Docker Compose is service discovery.","archived":false,"fork":false,"pushed_at":"2023-09-12T14:35:46.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T21:12:50.853Z","etag":null,"topics":["docker-compose","nginx","nodejs"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Washira.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-12T14:32:30.000Z","updated_at":"2023-09-12T14:37:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"23a3fa8d-c5bf-4552-8714-51ef3d410291","html_url":"https://github.com/Washira/docker-compose-and-nginx","commit_stats":null,"previous_names":["washira/docker-compose-and-nginx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Washira%2Fdocker-compose-and-nginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Washira%2Fdocker-compose-and-nginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Washira%2Fdocker-compose-and-nginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Washira%2Fdocker-compose-and-nginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Washira","download_url":"https://codeload.github.com/Washira/docker-compose-and-nginx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243510020,"owners_count":20302294,"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","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-compose","nginx","nodejs"],"created_at":"2024-11-19T17:56:34.134Z","updated_at":"2025-12-28T09:19:20.879Z","avatar_url":"https://github.com/Washira.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configuration\n\n## Files\n\n- service bundles (index.js, package.json, etc)\n- Dockerfile\n- docker-compose.yml\n\n## Docker Compose Commands\n\nInitially start a instance, you may stop by `ctrl` + `c`\n\n```\ndocker compose up\n```\n\nYou can connect service by port which you config in the service to listen such as `3000`\n\n## Start by Scaling Command\n\nBefore start you must \n- remove `posts` from `docker-compose.yml`\n- remove `container_name` from `docker-compose.yml` because `docker-compose` will config own itself\nby command below\n\n```\ndocker compose up --scale [service_name]=[number_of_instance_you_need]\n```\n\nexp.\n\n```\ndocker compose up --scale api=5\n```\n\nRight now you get 5 instances running, but how do the external aplication know which one instance they should connect to? In this case you need using NGINX\n\nRemove all instances with\n\n```\ndocker compose down\n```\n\nYou can build and run all instances to be background with this command\n\n```\ndocker compose up --scale [service_name]=[number_of_instance_you_need] -d --build\n```\n\n## Reverse Proxy and Load Balancer (NGINX)\n\nAdd another service in `docker-compose.yml`\n\n```\nservices:\n  ...\n\n  nginx:\n      image: nginx:latest\n      volumes:\n        - ./conf.d:/etc/nginx/conf.d\n      depends_on:\n        - api_test\n      ports:\n        - 8080:4000\n\n```\n\nIn part of \n\n```\n      volumes:\n        - ./conf.d:/etc/nginx/conf.d\n```\n\nfirst `conf.d` you can change to any, it should be same as the folder which contain `nginx.conf` and the path after that (`:/etc/nginx/conf.d`) must be fixed the example\n\nYou config external port is `80` and internal to connect service is `3000`\n\nNext, create folder `conf.d` and file `nginx.conf` inside it\n\nconfig reverse proxy by type inside the file with\n\n```\nserver {\n  listen 4000;\n  location / {\n    proxy_pass http://localhost:3000;\n  }\n}\n```\n\nIt means listening external request at port `8080` and forward to EGINX at port `4000`\n\nThen NGINX forward to url of service at port `3000` (AKA Reverse Proxy)\n\nYou can change the ports all that you want\n\n## Testing\n\nSend request at port `8080`\n\n```\nhttp://localhost:8080\n```\n\nYou may get response like\n\n```\n{\"message\":\"Hello from 07e2ada3ef6c\",\"hostname\":\"07e2ada3ef6c\"}\n```\n\nAnd if refresh, the hostname will change\nBecause of `Load Balancer` takes request to all instances by round rolling\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwashira%2Fdocker-compose-and-nginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwashira%2Fdocker-compose-and-nginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwashira%2Fdocker-compose-and-nginx/lists"}