{"id":18158130,"url":"https://github.com/seikho/node-dockerfile","last_synced_at":"2025-06-18T20:35:53.578Z","repository":{"id":65460443,"uuid":"37243161","full_name":"Seikho/node-dockerfile","owner":"Seikho","description":"A small library for programmatic generation of Dockerfiles using Node","archived":false,"fork":false,"pushed_at":"2017-09-07T08:34:07.000Z","size":60,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-08T22:16:07.579Z","etag":null,"topics":["docker","dockerfile","node","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/Seikho.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":"2015-06-11T06:22:29.000Z","updated_at":"2018-11-13T15:28:31.000Z","dependencies_parsed_at":"2023-01-24T14:45:20.606Z","dependency_job_id":null,"html_url":"https://github.com/Seikho/node-dockerfile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Seikho/node-dockerfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seikho%2Fnode-dockerfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seikho%2Fnode-dockerfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seikho%2Fnode-dockerfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seikho%2Fnode-dockerfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Seikho","download_url":"https://codeload.github.com/Seikho/node-dockerfile/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Seikho%2Fnode-dockerfile/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260629751,"owners_count":23038981,"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","dockerfile","node","typescript"],"created_at":"2024-11-02T07:05:39.457Z","updated_at":"2025-06-18T20:35:48.541Z","avatar_url":"https://github.com/Seikho.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Node-dockerfile\n\n[![NPM version](http://img.shields.io/npm/v/node-dockerfile.svg?style=flat)](https://www.npmjs.org/package/node-dockerfile)\n[![Travis build status](https://travis-ci.org/Seikho/node-dockerfile.svg?branch=master)](https://travis-ci.org/Seikho/node-dockerfile)   \nA small library for programmatic generation of Dockerfiles using Node.\n\nNode-dockerfile allows you to dynamically create Dockerfile files.  \nThis library was designed to allow us to dynamically create docker images to assist deployment automation.\n  \nWritten in TypeScript by Carl Winkler\n\n#### Installation\n\n```javascript\nnpm install node-dockerfile --save\n```\n\n#### Example usage\n```javascript\nimport { Builder } from 'node-dockerfile'\nconst dockerfile = new Builder();\n\n// Let's just add in a bunch of funky commands for a bit of fun\ndockerfile\n\t.from(\"node:6\")\n\t.newLine()\n\t.envs([\n\t\t{ key: 'NODE_ENV', value: 'developlement' },\n\t\t{ key: 'APP_ENV', value: 'dev' }\n\t])\n\t.comment(\"Clone and install dockerfile\")\n\t.run([\n\t\t\"apt-get install -y git\",\n\t\t\"git clone https://github.com/seikho/node-dockerfile /code/node-dockerfile\"\n \t])\n\t.newLine()\n\t.run([\"cd /code/node-dockerfile\", \"npm install\"]);\n\t.run(\"npm install -g http-server\")\n\t.env('NODE_ENV', 'production')\n\t.newLine()\n\t.workDir(\"/code/node-dockerfile\")\n\t.cmd(\"http-server\");\n\t\n// .write takes a callback which takes 'error' and 'content'.\n// Content being the content of the generated filed.\nconst cb = function(err, content) {\n\tif (err) console.log(\"Failed to write: %s\", err);\n\telse console.log(\"Successfully wrote the dockerfile!\"); \n}\n// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above.\n\ndockerfile.write(\".\", true, cb);\n\n// If all goes well...\n// Console: \u003e\u003e 'Successfully wrote to dockerfile!' \n```\n\n#### API\n\n**from(image: string)**\n```javascript\nmyFdockerfileile.from(\"ubuntu:latest\");\n// FROM ubuntu:latest  \n```\n\n**maintainer(maintainerName: string)**\n```javascript\ndockerfile.maintainer(\"Carl Winkler\");\n// MAINTAINER Carl Winkler\n```\n\n**run(instructions: string|string[])**\n```javascript\ndockerfile.run(\"apt-get intall -y curl\");\n// RUN apt-get install -y curl\n\n// We can create multi-line run commands\ndockerfile.run([\n\t\"apt-get install -y git\",\n\t\"git clone https://github.com/seikho/node-dockerfile.git\"\n]);\n/**\n * RUN apt-get install -y git \\\n * \u0026\u0026 git clone https://github.com/seikho/node-dockerfile.git\n */\n```\n\n**comment(comment: string)** Adds a comment to the file\n```javascript\ndockerfile.comment(\"This is a comment\");\n// # This is a comment\n```\n\n**newLine()** Adds a new line to the Dockerfile -- purely cosmetic\n\n**cmd(instructions: string|string[])**\n```javascript\ndockerfile.cmd(\"node --harmony index.js\");\n// CMD node --harmony index.js\n\ndockerfile.cmd([\"node\", \"--harmony\", \"index.js\"]);\n// '[\"node\", \"--harmony\", \"index.js\"]'\n```\n\n**label(key: string, label: string)**\n```javascript\ndockerfile.label(\"someLabel\", \"someValue\");\n// LABEL someLabel=someValue\n```\n\n**expose(port: number)**\n```javascript\ndockerfile.expose(8080);\n// EXPOSE 8080\n```\n\n**arg(key: string, value: string)**\n```javascript\ndockerfile.arg(\"user\", \"docker\");\n// ARG user=docker\n```\n\n**envs(pairs: Array\u003c{ key: string, value: string }\u003e)**\n```javascript\ndockerfile.envs([\n\t\t{ key: \"DOCKER_CERT_PATH\", value: \"/root/.docker/\" },\n\t\t{ key: \"NODE_ENV\", value: \"DEVELOPMENT\" }\n\t]);\n// ENV DOCKER_CERT_PATH=\"/root/.docker/\" \\ NODE_ENV=\"development\"\n```\n\n**env(key: string, value: string)**\n```javascript\ndockerfile.env(\"DOCKER_CERT_PATH\", \"/root/.docker/\");\n// ENV DOCKER_CERT_PATH=\"/root/.docker/\"\n```\n\n**add(source: string, destination: string)**\n```javascript\ndockerfile.add(\"hom*\", \"/mydir\");\n// ADD hom* /mydir/\n```\n\n**copy(source: string, destination: string)**\n```javascript\n// current working directory: /home/carl/projects/node-dockerfile\nvar dynamicPath = path.resolve(\"../my-library\"); // /home/carl/projects/my-library\ndockerfile.copy(dynamicPath, \"/code/my-library\");\n// COPY /home/carl/projects/my-library /code/my-library\n```\n\n**entryPoint(instructions: string|string[])**\n```javascript\ndockerfile.entryPoint(\"top -b\");\n// ENTRYPOINT top -b\n\ndockerfile.entryPoint([\"top\",\"-b\"]);\n// ENTRYPOINT [\"top\", \"-b\"]\n```\n\n**volume(volume: string)**\n```javascript\ndockerfile.volume(\"/some/volume\");\n// VOLUME /some/volume\n```\n\n**workDir(path: string)**\n```javascript\ndockerfile.workDir(\"/some/volume\");\n// WORKDIR /some/volume\n```\n\n**user(user: string)**\n```javascript\ndockerfile.user(\"carl\");\n// USER carl\n```\n\n**onBuild(instructions: string)**\n```javascript\ndockerfile.onBuild(\"ADD . /app/src\");\n// ONBUILD ADD . /app/src\n```\n\n**write(writeLocation: string, replaceExisting: boolean, callback: (error, content) =\u003e void))**\n\n```javascript\ndockerfile.write(\"../my-image\", true, function(err, content) {\n\tif (err) doSomethingElse();\n\telse doSuccessFunction();\n});\n```\n\n**writeStream()**\n\n```javascript\nvar fs = require('fs');\n\ndockerfile.writeStream()\n      .pipe(fs.createWriteStream('Dockerfile'));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseikho%2Fnode-dockerfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseikho%2Fnode-dockerfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseikho%2Fnode-dockerfile/lists"}