This was kind of a joke... you probably shouldn't actually do this.
Write your Dockerfile in javascript!
npm install -g dockerscript
from('debian', 'wheezy')
maintainer('you', 'your@email.com')
env('NGINX_VERSION', '1.7.11-1~wheezy')
run`
apt-key adv --keyserver pgp.mit.edu --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 &&
echo "deb http://nginx.org/packages/mainline/debian/ wheezy nginx" >> /etc/apt/sources.list &&
apt-get update &&
apt-get install -y ca-certificates nginx=$NGINX_VERSION &&
rm -rf /var/lib/apt/lists/*
`
comment('forward request and error logs to docker log collector')
run`
ln -sf /dev/stdout /var/log/nginx/access.log &&
ln -sf /dev/stderr /var/log/nginx/error.log
`
volume('/var/cache/nginx')
expose(80, 443)
cmd("nginx", "-g", "daemon off;")
this turns into:
FROM debian:wheezy
MAINTAINER you <your@email.com>
ENV NGINX_VERSION=1.7.11-1~wheezy
RUN apt-key adv --keyserver pgp.mit.edu --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && \
echo "deb http://nginx.org/packages/mainline/debian/ wheezy nginx" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install -y ca-certificates nginx=$NGINX_VERSION && \
rm -rf /var/lib/apt/lists/*
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
VOLUME /var/cache/nginx
EXPOSE 80 443
CMD ["nginx","-g","daemon off;"]
Run the dockerscript
command or use the ds
alias.
With no arguments, it looks for a dockerfile.js
in the current directory and writes to Dockerfile
in the current directory.
Your script will be passed through babel so you're free to use es6.
#Simple usage:
$ ls
dockerfile.js
$ ds
$ ls
Dockerfile dockerfile.js
#If you want to write to a different file, do this:
$ ds mydockerfile.js Dockerfile
#If you want to write to stdout, do this:
$ ds -
FROM ubuntu
...
#If you want to keep error logs, do this:
$ ds input.js Dockerfile.test dockerscript_errors.log
The following global functions are available to your dockerscript files:
You can use run
five different ways:
run('ls '+dir)
run('ls -l '+dir)
run('ls', '-l', dir)
run(['ls', '-l', dir])
run`ls -l ${dir}`
Using template tags you can easily pass in multiple lines. The linebreaks will be escaped for you.
run`
ls -l ${dir} &&
touch ${dir}/somethingElse
`
You can use cmd
in all of the same ways that you can use run
You can specify one port, or multiple.
expose(80)
expose(80, 443)
You can use env
two ways:
env('NODE_VERSION', '0.12.0')
env({
NODE_VERSION: '0.12.0',
NPM_VERSION: '2.5.1'
})
Don't worry about path whitespace, I got this.
Don't worry about path whitespace, I got this.
Works just like run
and cmd
.
Specify one or more.
Use it like this:
onbuild(function(){
run('echo', 'done building!')
})
The callback function will not be called on build, it's just for structure.
Docker doesn't allow multiple onbuild commands, so if you put more than one thing in here it won't work.
Grab a partial dockerscript file and include it. You can use this to break up your dockerfiles into manageable and reusable chunks.
Like require, the path is relative to the currently executing script. Unlike require, it does not return any exports. It's just for partials.
if (process.env.DOCKER_ENV == 'production') {
include('./monitoring')
add('./www', '/var/www')
} else if (process.env.DOCKER_ENV == 'development') {
include('./debugger')
volume('/var/www')
}
Contributors will be rewarded with a lifetime supply of imaginary pizza. :pizza: :pizza: :pizza:
If you send me a pull request that's good, I'll probably merge it.
Please follow some simple guidelines:
npm test
test
directory.If you need help with any of these things, let me know and I'll do my best to help you out.