{"id":19477451,"url":"https://github.com/ozbillwang/keycloak-compose","last_synced_at":"2025-04-25T14:32:33.517Z","repository":{"id":184772805,"uuid":"672452800","full_name":"ozbillwang/keycloak-compose","owner":"ozbillwang","description":"Run keycloak and keycloak cluster with docker compose - Up and Running in Seconds","archived":false,"fork":false,"pushed_at":"2024-02-14T06:39:27.000Z","size":49,"stargazers_count":9,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T23:06:02.158Z","etag":null,"topics":["authentication","devops","docker","docker-compose","keycloak","keycloak-cluster","security"],"latest_commit_sha":null,"homepage":"https://medium.com/@ozbillwang/keycloak-cluster-with-docker-compose-up-and-running-in-seconds-0c3223df4f75","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ozbillwang.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":"2023-07-30T06:12:34.000Z","updated_at":"2024-10-11T11:02:24.000Z","dependencies_parsed_at":"2023-07-30T07:27:28.829Z","dependency_job_id":"c98499bf-78cf-46f4-a748-d85553484052","html_url":"https://github.com/ozbillwang/keycloak-compose","commit_stats":null,"previous_names":["ozbillwang/keycloak-compose"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozbillwang%2Fkeycloak-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozbillwang%2Fkeycloak-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozbillwang%2Fkeycloak-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozbillwang%2Fkeycloak-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ozbillwang","download_url":"https://codeload.github.com/ozbillwang/keycloak-compose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250834215,"owners_count":21494930,"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":["authentication","devops","docker","docker-compose","keycloak","keycloak-cluster","security"],"created_at":"2024-11-10T19:44:56.168Z","updated_at":"2025-04-25T14:32:33.240Z","avatar_url":"https://github.com/ozbillwang.png","language":"Dockerfile","readme":"# keycloak-compose\n\nRun keycloak and postgresql with docker compose by two scenarios\n* [Keycloak with simple instance](https://github.com/ozbillwang/keycloak-compose/blob/master/README.md#keycloak-single-instance-with-docker-compose-up-and-running-inseconds)\n* [Keycloak with cluster (experimental for your understanding of how Keycloak clusters work)](https://github.com/ozbillwang/keycloak-compose/blob/master/README.md#keycloak-cluster-with-docker-compose-up-and-running-inseconds)\n\nThis repo is mainly set for my blogs\n\n[Run Keycloak in docker with extenal DB](https://medium.com/@ozbillwang/run-keycloak-in-docker-with-extenal-db-1b504ad00eae)\n\n[Run Keycloak locally with Docker compose](https://medium.com/@ozbillwang/run-keycloak-locally-with-docker-compose-db9a9f2fb437)\n\n[Keycloak Cluster with Docker Compose — Up and Running in Seconds](https://medium.com/@ozbillwang/keycloak-cluster-with-docker-compose-up-and-running-in-seconds-0c3223df4f75)\n\n[Keycloak Backup and Restore](https://medium.com/@ozbillwang/keycloak-backup-and-restore-eea87d294b3c)\n\n## Keycloak (single instance) with Docker Compose - Up and Running in Seconds\n\n### Prerequisite\n* [install docker](https://docs.docker.com/engine/install/)\n\n### Step 1\n\nupdate `/etc/hosts` , add below lines\n\n```\n# keycloak\n127.0.0.1 keycloak.com.au\n```\n\nOn Windows, the file path is usually: `c:\\Windows\\System32\\Drivers\\etc\\hosts`\n\n**Notes**: In many online documents and videos, Keycloak experts often recommend starting the Keycloak service on **localhost** with a specific port. However, this practice is not advisable, especially when working in a real environment. Instead, it’s more practical to configure Keycloak with a DNS-ready setup. This also allows you to test HTTPS access with SSL certifications later on if needed.\n\n### Step 2\n```\ngit clone https://github.com/ozbillwang/keycloak-compose.git\ncd keycloak-compose\ndocker compose up -d\ndocker ps -a\n```\nmake sure all containers running well\n### Step 3\n\naccess http://keycloak.com.au:8180\ngo with \"Administration Console \",  then login with `admin / password `\n\n![image](https://github.com/ozbillwang/keycloak-compose/assets/8954908/0c213c2a-cd7d-4235-b68a-43ca3dc809ec)\n\n## Keycloak Cluster with Docker Compose - Up and Running in Seconds\n\nYes, the solution is ready now with help from Niko Köbler (@dasniko) with [his cool video](https://www.youtube.com/watch?v=P96VQkBBNxU)\n\n### Step 1\n\nupdate `/etc/hosts` , add below lines\n\n```\n# keycloak\n127.0.0.1 keycloak.com.au\n```\n\nOn Windows, the file path is usually: `c:\\Windows\\System32\\Drivers\\etc\\hosts`\n\n### Step 2\n```\ngit clone https://github.com/ozbillwang/keycloak-compose.git\ncd keycloak-compose\ndocker compose -f docker-compose-cluster.yml up -d\n```\n\n* Check the health\n```\ndocker ps -a\n```\n![image](https://github.com/ozbillwang/keycloak-compose/assets/8954908/e97b6999-4464-4bad-94c6-39aaed386309)\n\n* Check logs with Cluster events\n\n```\ndocker logs -f \u003ckc1 or kc2 container id\u003e\n```\n\n![1_rSVRVOgXGqqzCHgmZmaAAg](https://github.com/ozbillwang/keycloak-compose/assets/8954908/d62be1fc-5468-41de-b964-eaee0079d4f4)\n\n* Check the cluster logs, there should be two members in cluster pool now\n\n\u003eReceived **new cluster view for channel** ISPN: [b31f28d4c94a-31765|1] (2) [b31f28d4c94a-31765, bc873530c08b-24274]\n\u003eStarting rebalance with members [b31f28d4c94a-31765, bc873530c08b-24274]\n\n\n### Step 3\n\naccess http://keycloak.com.au:8180\n\ngo with \"Administration Console \",  then login with `admin / password `\n\n### step 4\nTest the fail over and cluster realiable.\n\n* kill one keycloak container\n```\ndocker ps -a\ndocker rm -f keycloak-compose-kc2\n```\nCheck logs, you will only see one member in Cluster pool now.\n\n\u003e  Updating cache members list [b31f28d4c94a-31765], topology id 6\n\n![image](https://github.com/ozbillwang/keycloak-compose/assets/8954908/3bf3e0ea-e11a-4553-aba3-e61e9c288fb4)\n\nWhen you refresh the website http://keycloak.com.au:8180, it takes about 5~10 seconds at first time, then work as normal\n\n* restore all services\n```\n$ docker compose -f docker-compose-cluster.yml up -d\n\n ✔ Container db     Running \n ✔ Container kc1    Started    # because I killed it before\n ✔ Container kc2    Running \n ✔ Container kc_lb  Running\n```\nCheck logs again, two members in cluster pool now. \n\nIf you access http://keycloak.com.au:8180, it works fine\n\n\u003e Starting rebalance with members [b31f28d4c94a-31765, 462ae7fcf1a3-41736], phase READ_OLD_WRITE_ALL, topology id 7\n\u003e Finished rebalance with members [b31f28d4c94a-31765, 462ae7fcf1a3-41736], topology id 10\n\n![image](https://github.com/ozbillwang/keycloak-compose/assets/8954908/728ee4a4-10a2-4b8e-a6d7-8641fde0f6c0)\n\n### Reference\n\nhttps://www.keycloak.org/2019/05/keycloak-cluster-setup.html\n\nhttps://www.youtube.com/watch?v=P96VQkBBNxU\n\nhttps://www.keycloak.org/2019/08/keycloak-jdbc-ping\n\nhttp://jgroups.org/manual/#_jdbc_ping\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozbillwang%2Fkeycloak-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fozbillwang%2Fkeycloak-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozbillwang%2Fkeycloak-compose/lists"}