Skip to content

Instantly share code, notes, and snippets.

@kjendrzyca
Last active January 28, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjendrzyca/a284d398e3d022de3ed14e596c78089d to your computer and use it in GitHub Desktop.
Save kjendrzyca/a284d398e3d022de3ed14e596c78089d to your computer and use it in GitHub Desktop.
docker-run
#!/usr/bin/env node
const program = require('commander') // eslint-disable-line
program
.version('0.1.0')
.option('-r, --rebuild', 'Start the containers and rebuild the images')
.option('-d, --down', 'Stop the containers')
.option('-l, --logs', 'Log the output of all containers')
.option('-f, --follow', 'Log the output of all containers in watch mode')
.parse(process.argv)
const getArgs = () => {
if (program.rebuild) {
return ['up', '-d', '--build', '--force-recreate', '--remove-orphans']
}
if (program.down) {
return ['down', '--volumes', '--remove-orphans']
}
if (program.logs) {
return ['logs']
}
if (program.follow || (program.logs && program.follow)) {
return ['logs', '-f']
}
return ['up', '-d']
}
const opts = {stdio: 'inherit', shell: true}
require('child_process').spawn('docker-compose', getArgs(), opts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment