{"id":15068503,"url":"https://github.com/thenativeweb/crew","last_synced_at":"2025-08-14T18:38:33.540Z","repository":{"id":23368259,"uuid":"26729502","full_name":"thenativeweb/crew","owner":"thenativeweb","description":"crew makes managing Docker a breeze.","archived":false,"fork":false,"pushed_at":"2023-10-26T06:33:39.000Z","size":86,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-29T13:40:59.395Z","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/thenativeweb.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-16T21:58:53.000Z","updated_at":"2022-11-13T16:27:15.000Z","dependencies_parsed_at":"2024-06-19T20:14:00.005Z","dependency_job_id":null,"html_url":"https://github.com/thenativeweb/crew","commit_stats":{"total_commits":120,"total_committers":2,"mean_commits":60.0,"dds":"0.17500000000000004","last_synced_commit":"02d7e33e82ecd78b22c2a49820181632fe643e7c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fcrew","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fcrew/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fcrew/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fcrew/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thenativeweb","download_url":"https://codeload.github.com/thenativeweb/crew/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219854911,"owners_count":16556181,"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":[],"created_at":"2024-09-25T01:37:52.939Z","updated_at":"2024-10-13T04:03:53.347Z","avatar_url":"https://github.com/thenativeweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crew\n\ncrew makes managing Docker a breeze.\n\n## Installation\n\n    $ npm install crew\n\n## Quick start\n\nFirst you need to add a reference to crew to to your application.\n\n```javascript\nconst crew = require('crew');\n```\n\nTo connect to a Docker server, call the `crew` function and provide the hostname as well as the port. Additionally, you need to provide a private key and a certificate for client-side authentication, and a CA certificate for server-side authentication.\n\nYou may use the environment variables `DOCKER_HOST` and `DOCKER_CERT_PATH` to get appropriate values.\n\n```javascript\ncrew({\n  host: url.parse(process.env.DOCKER_HOST).hostname,\n  port: url.parse(process.env.DOCKER_HOST).port,\n  keys: {\n    privateKey: fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'key.pem')),\n    certificate: fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'cert.pem')),\n    caCertificate: fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'ca.pem'))\n  }\n}, (err, dockWorker) =\u003e {\n  // ...\n});\n```\n\nPlease note that the initially provided options are available at `dockWorker.options`.\n\n### Pinging Docker\n\nTo ping the Docker server, use the `ping` function.\n\n```javascript\ndockWorker.ping(err =\u003e {\n  // ...\n});\n```\n\n### Verifying that an image is available\n\nIf you need to verify whether an image is available on the Docker server, use the `hasImage` function and provide the name of the image.\n\n```javascript\ndockWorker.hasImage({ name: 'node' }, (err, hasImage) =\u003e {\n  console.log(hasImage); // =\u003e true\n  // ...\n});\n```\n\n`hasImage` also supports tags to check for a particular version of an image, as in the following example.\n\n```javascript\ndockWorker.hasImage({ name: 'node', tag: '4.0' }, (err, hasImage) =\u003e {\n  console.log(hasImage); // =\u003e true\n  // ...\n});\n```\n\n### Downloading an image\n\nTo download an image to the Docker server, use the `downloadImage` function and provide the name of the image.\n\n```javascript\ndockWorker.downloadImage({ name: 'node' }, err =\u003e {\n  // ...\n});\n```\n\n If you want to download a specific version, add the tag to the name of the image.\n\n```javascript\ndockWorker.downloadImage({ name: 'node', tag: '4.0' }, err =\u003e {\n  // ...\n});\n```\n\nIf you don't specify a tag, the tag `latest` will be used which is also the default used by the Docker CLI.\n\n### Building an image\n\nTo build an image, call the `buildImage` function and provide the directory you want to use, a `Dockerfile`, and the name of the image.\n\n```javascript\ndockWorker.buildImage({\n  directory: __dirname,\n  dockerfile: path.join(__dirname, 'my-dockerfile'),\n  name: 'myImage'\n}, err =\u003e {\n  // ...\n});\n```\n\n`buildImage` also supports tags fors images by passing in the optional `tag` option.\n\n```javascript\ndockWorker.buildImage({\n  directory: __dirname,\n  dockerfile: path.join(__dirname, 'my-dockerfile'),\n  name: 'myImage',\n  tag: '0.1.0'\n}, err =\u003e {\n  // ...\n});\n```\n\nIf you want to exclude some files from the newly built image, you can use the `dockerignore` property to provide the path to an ignore file.\n\n```javascript\ndockWorker.buildImage({\n  directory: __dirname,\n  dockerfile: path.join(__dirname, 'my-dockerfile'),\n  dockerignore: path.join(__dirname, 'my-dockerignore'),\n  name: 'myImage'\n}, err =\u003e {\n  // ...\n});\n```\n\nIf you want to modify the build context right before the image gets built, register a `preBuild` hook and do whatever you want to do.\n\n```javascript\ndockWorker.buildImage({\n  directory: __dirname,\n  dockerfile: path.join(__dirname, 'my-dockerfile'),\n  dockerignore: path.join(__dirname, 'my-dockerignore'),\n  preBuild: (preBuildOptions, done) =\u003e {\n    console.log(preBuildOptions);\n    // =\u003e {\n    //      directory: '...'\n    //    }\n\n    done(null);\n  },\n  name: 'myImage'\n}, err =\u003e {\n  // ...\n});\n```\n\n### Starting a container\n\nTo create and start a container, call the `startContainer` function and provide the name of the image and the desired container name. This returns the newly created container's id.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer'\n}, (err, id) =\u003e {\n  console.log(id); // =\u003e '70073a08b0f7fdfef44ca6fe03ba5e796d4773d9628b6f68eb7e34568dc73e1f'\n  // ...\n});\n```\n\n`startContainer` also supports image tags.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  tag: '4.0',\n  name: 'myContainer'\n}, (err, id) =\u003e {\n  console.log(id); // =\u003e '70073a08b0f7fdfef44ca6fe03ba5e796d4773d9628b6f68eb7e34568dc73e1f'\n  // ...\n});\n```\n\n#### Restarting crashed containers\n\nIf you want your container to restart automatically on crashes, add the `restart` property to the parameter object and set it to `true`.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  restart: true\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n#### Forwarding ports\n\nTo forward container ports to the host, add the `ports` property to the parameter object and hand over an array of forwardings.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  ports: [\n    { container: 3000, host: 80 }\n  ]\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n#### Setting environment variables\n\nTo set environment variables, add the `env` property to the parameter object and hand over the keys and values you want to use as environment variables.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  env: {\n    port: 3000\n  }\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n#### Using volumes\n\nTo use volumes from the host, add the `volumes` property to the parameter object and hand over an array of volume mappings.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  volumes: [\n    { container: '/data', host: '/home/janedoe/foo' }\n  ]\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n#### Using links\n\nTo link a container to another one, add the `links` property to the parameter object and hand over an array of link mappings.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  links: [\n    { name: 'mongodb', alias: 'db' }\n  ]\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n#### Configuring network settings\n\nTo add extra hosts to the container's `/etc/hosts` file, add the `network` property to the parameter object and assign a `hosts` property to it.\n\n```javascript\ndockWorker.startContainer({\n  image: 'node',\n  name: 'myContainer',\n  network: {\n    hosts: [\n      { name: 'example.com', ip: '192.168.0.1' }\n    ]\n  }\n}, (err, id) =\u003e {\n  // ...\n});\n```\n\n### Getting information on running containers\n\nTo get information on running containers for a specific image, use the `getRunningContainersFor` function and provide the image name.\n\n```javascript\ndockWorker.getRunningContainersFor({ name: 'node' }, (err, containers) =\u003e {\n  console.log(containers);\n  // =\u003e [\n  //      {\n  //        image: 'node',\n  //        name: 'my-container',\n  //        ports: [\n  //          { container: 3000, host: 3000 }\n  //        ],\n  //        env: {\n  //          PORT: '3000'\n  //        },\n  //        volumes: [\n  //          { container: '/data', host: '/home/janedoe/foo' }\n  //        ],\n  //        links: [\n  //          { name: 'your-container', alias: 'yours' }\n  //        ],\n  //        network: {\n  //          hosts: [\n  //            { name: 'example.com', ip: '192.168.0.1' }\n  //          ]\n  //        }\n  //      }\n  //    ]\n});\n```\n\nAgain, you may also specify an image tag.\n\n```javascript\ndockWorker.getRunningContainersFor({ name: 'node', tag: '4.0' }, (err, containers) =\u003e {\n  // ...\n});\n```\n\nAlternatively you may specify the image name by a regular expression.\n\n```javascript\ndockWorker.getRunningContainersFor(/^no/, (err, containers) =\u003e {\n  // ...\n});\n```\n\n### Getting logs of a container\n\nTo get the logs of a running container, call the `getLogs` function and provide the name of the container.\n\n```javascript\ndockWorker.getLogs('myContainer', (err, stdOut, stdErr) =\u003e {\n  // ...\n});\n```\n\n### Stopping a container\n\nTo stop and automatically remove a running container, call the `stopContainer` function and provide the name of the container.\n\n```javascript\ndockWorker.stopContainer('myContainer', err =\u003e {\n  // ...\n});\n```\n\n## Running the build\n\nThis module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed crew and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed.\n\n    $ grunt\n\nIf you're using Docker Machine, make sure to copy the crew source folder to your Docker Machine before running the tests. Assuming your Docker machine name is `dev` and you're in the `crew` source folder on your local machine run the following commands.\n\n```bash\ndocker-machine ssh dev -- mkdir -p $(pwd)\ndocker-machine scp -r . dev:$(pwd)\n```\n\nAfter this, you can run the tests as described above.\n\n## License\n\nThe MIT License (MIT)\nCopyright (c) 2014-2015 the native web.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fcrew","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenativeweb%2Fcrew","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fcrew/lists"}