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
npm install node-dockerfile --save
Example usage
const dockerfile = ; // Let's just add in a bunch of funky commands for a bit of fundockerfile ; ; // .write takes a callback which takes 'error' and 'content'.// Content being the content of the generated filed.const cb = { if err console; else console; }// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above. dockerfile; // If all goes well...// Console: >> 'Successfully wrote to dockerfile!'
API
from(image: string)
myFdockerfileile;// FROM ubuntu:latest
maintainer(maintainerName: string)
dockerfile;// MAINTAINER Carl Winkler
run(instructions: string|string[])
dockerfile;// RUN apt-get install -y curl // We can create multi-line run commandsdockerfile;/** * RUN apt-get install -y git \ * && git clone https://github.com/seikho/node-dockerfile.git */
comment(comment: string) Adds a comment to the file
dockerfile;// # This is a comment
newLine() Adds a new line to the Dockerfile -- purely cosmetic
cmd(instructions: string|string[])
dockerfile;// CMD node --harmony index.js dockerfile;// '["node", "--harmony", "index.js"]'
label(key: string, label: string)
dockerfilelabel"someLabel" "someValue";// LABEL someLabel=someValue
expose(port: number)
dockerfile;// EXPOSE 8080
arg(key: string, value: string)
dockerfile;// ARG user=docker
envs(pairs: Array<{ key: string, value: string }>)
dockerfile;// ENV DOCKER_CERT_PATH="/root/.docker/" \ NODE_ENV="development"
env(key: string, value: string)
dockerfile;// ENV DOCKER_CERT_PATH="/root/.docker/"
add(source: string, destination: string)
dockerfile;// ADD hom* /mydir/
copy(source: string, destination: string)
// current working directory: /home/carl/projects/node-dockerfilevar dynamicPath = path; // /home/carl/projects/my-librarydockerfile;// COPY /home/carl/projects/my-library /code/my-library
entryPoint(instructions: string|string[])
dockerfile;// ENTRYPOINT top -b dockerfile;// ENTRYPOINT ["top", "-b"]
volume(volume: string)
dockerfile;// VOLUME /some/volume
workDir(path: string)
dockerfile;// WORKDIR /some/volume
user(user: string)
dockerfile;// USER carl
onBuild(instructions: string)
dockerfile;// ONBUILD ADD . /app/src
write(writeLocation: string, replaceExisting: boolean, callback: (error, content) => void))
dockerfile;
writeStream()
var fs = ; dockerfile ;