{"id":19241078,"url":"https://github.com/binocarlos/flocker","last_synced_at":"2025-07-25T16:08:53.300Z","repository":{"id":19571553,"uuid":"22820938","full_name":"binocarlos/flocker","owner":"binocarlos","description":"treat a flock of dockers as a single docker server","archived":false,"fork":false,"pushed_at":"2014-08-23T20:07:54.000Z","size":236,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T11:50:42.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/binocarlos.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-08-10T23:18:36.000Z","updated_at":"2017-07-31T04:42:15.000Z","dependencies_parsed_at":"2022-08-24T13:40:44.123Z","dependency_job_id":null,"html_url":"https://github.com/binocarlos/flocker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/binocarlos/flocker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fflocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fflocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fflocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fflocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binocarlos","download_url":"https://codeload.github.com/binocarlos/flocker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fflocker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267029407,"owners_count":24024199,"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-07-25T02:00:09.625Z","response_time":70,"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-11-09T17:10:11.384Z","updated_at":"2025-07-25T16:08:53.254Z","avatar_url":"https://github.com/binocarlos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"flocker\n-------\n\ntreat a flock of dockers as a single docker server\n\nsimilar to the [libswarm](https://github.com/docker/libswarm) aggregate backend\n\n## install\n\n```\n$ npm install flocker\n```\n\n## usage\n\nA flocker proxy will route HTTP requests from the standard docker client back to a collection of docker hosts.\n\nYou pass functions to decide on routing and to list the current inventory.\n\n```js\nvar http = require('http')\nvar flocker = require(\"flocker\")\n\nvar dockers = flocker()\n\n// we need a list of all servers in our cluster\ndockers.on('list', function(next){\n\n\t// we can load the list from a database\n\t// it should return an array of server objects\n\tlistServers(next)\n})\n\n// we need to route a container onto a single server\ndockers.on('route', function(info, next){\n\tif(info.container){\n\t\t// route based on the container info\n\t\tvar containerName = info.name\n\t\tvar containerInfo = info.container\n\n\t\t// you can remap properties of the container before it reaches the docker server\n\t\tnext(null, server)\n\t}\n\telse if(info.image){\n\t\t// route based on the image name\n\t\tvar imageName = info.image\n\t\tnext(null, server)\n\t}\n})\n\ndockers.on('map', function(name, containerJSON, imageJSON, next){\n\n\t// here we can change properties of the container before it is launched\n\t// we can also study the image for exposed ports and volumes\n\t\n})\n\ndockers.on('start', function(name, containerJSON, imageJSON, bootJSON, next){\n\n\t// here we can change properties of the bootJSON record\n\t// the container and image have been created and so are immutable\n\t\n})\n\nvar server = http.createServer(function(req, res){\n\n\t// we can do custom auth/routing logic here\n\tdockers.handle(req, res)\t\n})\n\n// this is important if we want docker attach to work\nserver.httpAllowHalfOpen = true\n\n// we now have a multi-docker server compatable with the standard docker client\nserver.listen(80)\n```\n\n## api\n\n#### `var dockers = flocker()`\n\nCreate a new flocker proxy\n\n## events\n\n#### `dockers.on('route', function(info, next){})`\n\nCalled when a new container needs allocating to a docker server\n\nThis function is your chance to customize your network by changing what server / environment variables etc\n\nif it is a container then info is an object with the following properties:\n\n * name - the name of the container\n * image - the name of the image\n * container - the JSON object describing the container\n\nif it is an image, then info is an object with the following properties:\n\n * image - the name of the image\n\nIt is up to you to keep state between `POST /containers/create` and `POST /images/create` for `docker run` commands\n\nCall next with a string representing the docker server to send the request to e.g. `127.0.0.1:2375`\n\nAny changes made to the info will apply to the forwarded request - this lets you intercepts create requests and route them where you choose and change environment variables etc\n\n```js\ndockers.on('route', function(info, next){\n\tdoSomeAsyncStuff(function(err, meta){\n\t\tinfo.container.name = meta.name\n\t\tnext(null, meta.server)\n\t})\n})\n```\n\n#### `dockers.on('map', function(name, containerJSON, imageJSON, next){})`\n\nCalled just before calling /containers/create but once the image has been downloaded onto the machine\n\nYou can change the properties of container - image is immutable but contains the data for the image (this can be used to discover ports from within the Dockerfile not mentioned in the docker run command)\n\n\n```js\ndockers.on('map', function(name, containerJSON, imageJSON, next){\n\n\t// change properties of the container\n\t// read properties of the image\n\n\tnext()\n})\n```\n\n\n#### `dockers.on('start', function(name, containerJSON, imageJSON, bootJSON, next){})`\n\nCalled when a request to /containers/start is captured.\n\ncontainerJSON and imageJSON are the records loaded from the already routed docker server and are immutable.\n\nbootJSON is the JSON body of the /containers/start request and can be changed\n\n```js\ndockers.on('map', function(name, containerJSON, imageJSON, bootJSON, next){\n\n\t// change properties of the bootJSON\n\t// read properties of the image and container\n\n\tnext()\n})\n```\n\n#### `dockers.on('list', function(next){})`\n\nCalled when the proxy needs a list of all current servers\n\nAn array of docker endpoint strings should be returned\n\n```js\nvar dockerServers = [{\n\thostname:'node1',\n\tdocker:'192.168.8.120:2375'\n},{\n\thostname:'node2',\n\tdocker:'192.168.8.121:2375'\n},{\n\thostname:'node3',\n\tdocker:'192.168.8.122:2375'\n}]\n\ndockers.on('list', function(next){\n\tnext(null, dockerServers)\n})\n```\n\n#### `server.httpAllowHalfOpen`\n\nBecause of the way docker attach works - you must set this property to true on the http server to allow attach traffic to travel via the proxy\n\n```js\n// this is important if we want docker attach to work\nserver.httpAllowHalfOpen = true\nserver.listen(80)\n```\n\n## license\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fflocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinocarlos%2Fflocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fflocker/lists"}