# node-dockerfile

> A dockerfile composer using Node

Latest version **0.7.1** (published 2017-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-dockerfile
pnpm add node-dockerfile
yarn add node-dockerfile
bun add node-dockerfile
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.1 |
| Published | 2017-09-07 |
| First published | 2015-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Carl Winkler |
| Maintainers | seikho |
| Keywords | node, docker, dockerfile, builder, composer |

## Links

- npm: https://www.npmjs.com/package/node-dockerfile
- Repository: https://github.com/seikho/node-dockerfile
- Issues: https://github.com/seikho/node-dockerfile/issues
- npm.io page: https://npm.io/package/node-dockerfile

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.7.1 (latest) — 2017-09-07
- 0.7.0 — 2017-09-07
- 0.6.2 — 2017-02-20
- 0.6.1 — 2017-02-20
- 0.6.0 — 2017-02-20
- 0.5.1 — 2017-02-17
- 0.5.0 — 2017-02-17
- 0.4.2 — 2017-02-17
- 0.4.1 — 2017-02-16
- 0.4.0 — 2017-02-16
- 0.3.4 — 2015-11-09
- 0.3.3 — 2015-10-08
- 0.3.2 — 2015-10-07
- 0.3.1 — 2015-10-07
- 0.3.0 — 2015-10-07
- … 4 more at https://npm.io/package/node-dockerfile/versions

## README

### Node-dockerfile

[![NPM version](http://img.shields.io/npm/v/node-dockerfile.svg?style=flat)](https://www.npmjs.org/package/node-dockerfile)
[![Travis build status](https://travis-ci.org/Seikho/node-dockerfile.svg?branch=master)](https://travis-ci.org/Seikho/node-dockerfile)   
A small library for programmatic generation of Dockerfiles using Node.

Node-dockerfile allows you to dynamically create Dockerfile files.  
This library was designed to allow us to dynamically create docker images to assist deployment automation.
  
Written in TypeScript by Carl Winkler

#### Installation

```javascript
npm install node-dockerfile --save
```

#### Example usage
```javascript
import { Builder } from 'node-dockerfile'
const dockerfile = new Builder();

// Let's just add in a bunch of funky commands for a bit of fun
dockerfile
	.from("node:6")
	.newLine()
	.envs([
		{ key: 'NODE_ENV', value: 'developlement' },
		{ key: 'APP_ENV', value: 'dev' }
	])
	.comment("Clone and install dockerfile")
	.run([
		"apt-get install -y git",
		"git clone https://github.com/seikho/node-dockerfile /code/node-dockerfile"
 	])
	.newLine()
	.run(["cd /code/node-dockerfile", "npm install"]);
	.run("npm install -g http-server")
	.env('NODE_ENV', 'production')
	.newLine()
	.workDir("/code/node-dockerfile")
	.cmd("http-server");
	
// .write takes a callback which takes 'error' and 'content'.
// Content being the content of the generated filed.
const cb = function(err, content) {
	if (err) console.log("Failed to write: %s", err);
	else console.log("Successfully wrote the dockerfile!"); 
}
// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above.

dockerfile.write(".", true, cb);

// If all goes well...
// Console: >> 'Successfully wrote to dockerfile!' 
```

#### API

**from(image: string)**
```javascript
myFdockerfileile.from("ubuntu:latest");
// FROM ubuntu:latest  
```

**maintainer(maintainerName: string)**
```javascript
dockerfile.maintainer("Carl Winkler");
// MAINTAINER Carl Winkler
```

**run(instructions: string|string[])**
```javascript
dockerfile.run("apt-get intall -y curl");
// RUN apt-get install -y curl

// We can create multi-line run commands
dockerfile.run([
	"apt-get install -y git",
	"git clone https://github.com/seikho/node-dockerfile.git"
]);
/**
 * RUN apt-get install -y git \
 * && git clone https://github.com/seikho/node-dockerfile.git
 */
```

**comment(comment: string)** Adds a comment to the file
```javascript
dockerfile.comment("This is a comment");
// # This is a comment
```

**newLine()** Adds a new line to the Dockerfile -- purely cosmetic

**cmd(instructions: string|string[])**
```javascript
dockerfile.cmd("node --harmony index.js");
// CMD node --harmony index.js

dockerfile.cmd(["node", "--harmony", "index.js"]);
// '["node", "--harmony", "index.js"]'
```

**label(key: string, label: string)**
```javascript
dockerfile.label("someLabel", "someValue");
// LABEL someLabel=someValue
```

**expose(port: number)**
```javascript
dockerfile.expose(8080);
// EXPOSE 8080
```

**arg(key: string, value: string)**
```javascript
dockerfile.arg("user", "docker");
// ARG user=docker
```

**envs(pairs: Array<{ key: string, value: string }>)**
```javascript
dockerfile.envs([
		{ key: "DOCKER_CERT_PATH", value: "/root/.docker/" },
		{ key: "NODE_ENV", value: "DEVELOPMENT" }
	]);
// ENV DOCKER_CERT_PATH="/root/.docker/" \ NODE_ENV="development"
```

**env(key: string, value: string)**
```javascript
dockerfile.env("DOCKER_CERT_PATH", "/root/.docker/");
// ENV DOCKER_CERT_PATH="/root/.docker/"
```

**add(source: string, destination: string)**
```javascript
dockerfile.add("hom*", "/mydir");
// ADD hom* /mydir/
```

**copy(source: string, destination: string)**
```javascript
// current working directory: /home/carl/projects/node-dockerfile
var dynamicPath = path.resolve("../my-library"); // /home/carl/projects/my-library
dockerfile.copy(dynamicPath, "/code/my-library");
// COPY /home/carl/projects/my-library /code/my-library
```

**entryPoint(instructions: string|string[])**
```javascript
dockerfile.entryPoint("top -b");
// ENTRYPOINT top -b

dockerfile.entryPoint(["top","-b"]);
// ENTRYPOINT ["top", "-b"]
```

**volume(volume: string)**
```javascript
dockerfile.volume("/some/volume");
// VOLUME /some/volume
```

**workDir(path: string)**
```javascript
dockerfile.workDir("/some/volume");
// WORKDIR /some/volume
```

**user(user: string)**
```javascript
dockerfile.user("carl");
// USER carl
```

**onBuild(instructions: string)**
```javascript
dockerfile.onBuild("ADD . /app/src");
// ONBUILD ADD . /app/src
```

**write(writeLocation: string, replaceExisting: boolean, callback: (error, content) => void))**

```javascript
dockerfile.write("../my-image", true, function(err, content) {
	if (err) doSomethingElse();
	else doSuccessFunction();
});
```

**writeStream()**

```javascript
var fs = require('fs');

dockerfile.writeStream()
      .pipe(fs.createWriteStream('Dockerfile'));
```

---
_Source: https://npm.io/package/node-dockerfile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
