{"id":13651522,"url":"https://github.com/foostan/consul-with-docker","last_synced_at":"2025-08-09T06:29:07.723Z","repository":{"id":146671950,"uuid":"25743609","full_name":"foostan/consul-with-docker","owner":"foostan","description":"The environment of Consul with Docker include Consul Template and Registrator","archived":false,"fork":false,"pushed_at":"2015-11-28T08:40:40.000Z","size":8,"stargazers_count":58,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T00:12:06.667Z","etag":null,"topics":["consul","docker"],"latest_commit_sha":null,"homepage":"","language":null,"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/foostan.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}},"created_at":"2014-10-25T19:25:15.000Z","updated_at":"2023-08-23T13:15:36.000Z","dependencies_parsed_at":"2023-05-28T22:15:47.747Z","dependency_job_id":null,"html_url":"https://github.com/foostan/consul-with-docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foostan%2Fconsul-with-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foostan%2Fconsul-with-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foostan%2Fconsul-with-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foostan%2Fconsul-with-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foostan","download_url":"https://codeload.github.com/foostan/consul-with-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250248860,"owners_count":21399350,"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":["consul","docker"],"created_at":"2024-08-02T02:00:50.248Z","updated_at":"2025-04-22T13:32:43.297Z","avatar_url":"https://github.com/foostan.png","language":null,"funding_links":[],"categories":["Projects"],"sub_categories":["Provisioning"],"readme":"consul-with-docker\n=================\n\nConsul Template and Registrator(https://github.com/gliderlabs/registrator) have good chemistry, and combine Consul and Docker effectively.\nFor example, they enable to update HAProxy node that is running on Docker easy and quickly, in real time.\n\nThis repository is environment of Consul with Docker include Consul Template and Registrator.\nUsage is here in Japanese http://fstn.hateblo.jp/entry/2014/10/26/153247\n\n## Overview\n![Overview Figure](http://cdn-ak.f.st-hatena.com/images/fotolife/f/foostan/20141026/20141026021814.png)\n\nA Virtual Machine include these packages\n\n- Docker\n- Consul\n- Consul Template\n- Registrator\n- HAProxy\n\nand, the endpoint of web services is `192.168.33.11:80` in this environment.\n\n## Prepare environment\n\n### Build by Vagrant and Ansible\n\n```\n$ git clone https://github.com/foostan/consul-with-docker.git\n$ cd consul-with-docker\n$ vagrant up\n```\n\n### Run Consul agent\n\n```\nvagrant@node-1:~$ consul agent -data-dir=/tmp/consul -server -bootstrap\n==\u003e WARNING: Bootstrap mode enabled! Do not enable unless necessary\n==\u003e WARNING: It is highly recommended to set GOMAXPROCS higher than 1\n==\u003e Starting Consul agent...\n==\u003e Starting Consul agent RPC...\n==\u003e Consul agent running!\n         Node name: 'node-1'\n        Datacenter: 'dc1'\n            Server: true (bootstrap: true)\n       Client Addr: 127.0.0.1 (HTTP: 8500, DNS: 8600, RPC: 8400)\n      Cluster Addr: 10.0.2.15 (LAN: 8301, WAN: 8302)\n    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false\n```\n\n### Run Consul template\n```\nvagrant@node-1:~$ sudo consul-template\\\n -consul=localhost:8500\\\n -template=\"/vagrant/haproxy.ctmpl:/etc/haproxy/haproxy.cfg:service haproxy reload\"\n```\n\n## Run Registrator\n```\nvagrant@node-1:~$ registrator consul:\n```\n\n## Build tinyweb and Run a container\n\n### Build tinyweb\nTinyweb is a simple web server for a test environment by nc command.\n\n```\nvagrant@node-1:~$ docker build -t foostan/tinyweb /vagrant/tinyweb/\n```\n\n### Run a container\n\n```\ndocker run -p 80 -d foostan/tinyweb\nc437b2717b76dde8c31211fea09bc5bb60b8c16892161db24cb31a1b49543ae1\nvagrant@node-1:~$ docker ps\nCONTAINER ID        IMAGE                    COMMAND                CREATED             STATUS              PORTS                   NAMES\nc437b2717b76        foostan/tinyweb:latest   \"\\\"/bin/sh -c 'while   5 minutes ago       Up 5 minutes        0.0.0.0:49178-\u003e80/tcp   romantic_carson\n```\n\n## Check\nAdd a tinyweb service in consul by Registrator and update HAProxy configuration by Consul Template after running a container.\n\nCheck Consul services\n\n```\n$ curl -s localhost:8500/v1/catalog/services | jq .\n{\n  \"consul\": [],\n  \"tinyweb\": []\n}\nvagrant@node-1:~$ curl -s localhost:8500/v1/catalog/service/tinyweb | jq .\n[\n  {\n    \"Node\": \"node-1\",\n    \"Address\": \"10.0.2.15\",\n    \"ServiceID\": \"node-1:romantic_carson:80\",\n    \"ServiceName\": \"tinyweb\",\n    \"ServiceTags\": null,\n    \"ServicePort\": 49178\n  }\n]\n```\nAdded tinyweb and registrated address and port of a node.\n\nCheck HAProxy\n\n```\nvagrant@node-1:~$ tail -n 7 /etc/haproxy/haproxy.cfg\n\nfrontend  main *:80\n    default_backend    tinyweb\n\nbackend tinyweb\n    balance roundrobin\n    server node-1:romantic_carson:80 10.0.2.15:49178 check\n```\n\nUpdated the HAProxy configuration.\n\nAccess check\n\n```\nvagrant@node-1:~$ curl localhost\nc437b2717b76\n```\n\nWithout a virtual machine\n```\n$ curl 192.168.33.11\nc437b2717b76\n```\n\n### Run and kill multiple containers\nRun 5 containers\n\n```\nvagrant@node-1:~$ docker run -d -p 80 foostan/tinyweb\ndf9d19738e7610c448478c94ec10ab63259a2c78cfbe6437de2d3e7a8870b63e\nvagrant@node-1:~$ docker run -d -p 80 foostan/tinyweb\nb7ddc05c645490c21c18b98161bef0994b9c2ad366ff6e85a0b45652ff204e6d\nvagrant@node-1:~$ docker run -d -p 80 foostan/tinyweb\n0c31735035d4da4519ebbe7a6957ddb9bc1f865e5448c9ab838a742bff3178d3\nvagrant@node-1:~$ docker run -d -p 80 foostan/tinyweb\n8be6547a4a418faf34be1727b40386c149dd34d41ce5f8efb8c37d37050849ee\nvagrant@node-1:~$ docker run -d -p 80 foostan/tinyweb\na7969a2dfa63d137d77369b5e9c519b5565ec0bc2b14126c300b24c11c25deb5\n```\n\nUpdated the HAProxy configuration\n\n```\nvagrant@node-1:~$ tail -n 12 /etc/haproxy/haproxy.cfg\n\nfrontend  main *:80\n    default_backend    tinyweb\n\nbackend tinyweb\n    balance roundrobin\n    server node-1:hopeful_newton:80 10.0.2.15:49181 check\n    server node-1:hopeful_torvalds:80 10.0.2.15:49179 check\n    server node-1:naughty_elion:80 10.0.2.15:49182 check\n    server node-1:romantic_carson:80 10.0.2.15:49178 check\n    server node-1:sad_darwin:80 10.0.2.15:49180 check\n    server node-1:thirsty_kowalevski:80 10.0.2.15:49183 check\n```\n\nAccess check\n```\n$ curl 192.168.33.11\n0c31735035d4\n$ curl 192.168.33.11\ndf9d19738e76\n$ curl 192.168.33.11\n8be6547a4a41\n$ curl 192.168.33.11\nc437b2717b76\n$ curl 192.168.33.11\nb7ddc05c6454\n$ curl 192.168.33.11\na7969a2dfa63\n```\n\nKill containers and Updated the HAProxy configuration\n```\nvagrant@node-1:~$ docker kill a7969a2dfa63 b7ddc05c6454 c437b2717b76\na7969a2dfa63\nb7ddc05c6454\nc437b2717b76\nvagrant@node-1:~$ tail -n 9 /etc/haproxy/haproxy.cfg\n\nfrontend  main *:80\n    default_backend    tinyweb\n\nbackend tinyweb\n    balance roundrobin\n    server node-1:hopeful_newton:80 10.0.2.15:49181 check\n    server node-1:hopeful_torvalds:80 10.0.2.15:49179 check\n    server node-1:naughty_elion:80 10.0.2.15:49182 check\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoostan%2Fconsul-with-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoostan%2Fconsul-with-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoostan%2Fconsul-with-docker/lists"}