Skip to content

Instantly share code, notes, and snippets.

@tjmehta
Created February 9, 2016 23:09
Show Gist options
  • Save tjmehta/33c87502956cb4cc56ee to your computer and use it in GitHub Desktop.
Save tjmehta/33c87502956cb4cc56ee to your computer and use it in GitHub Desktop.
Publish all expose ports to 1-to-1 w/ docker host
#!/usr/bin/env node
# Usage: docker run [..opts] `publish-static <image>:<tag>`
'use strict'
const execSync = require('child_process').execSync
const image = process.argv[2]
const inspect = JSON.parse(
execSync('docker inspect ' + image).toString()
)
const ports = Object.keys(inspect[0].ContainerConfig.ExposedPorts)
let out = ports.reduce(function (str, p, i) {
const port = p.split('/')[0]
str += `-p=${port}:${port} `
return str
}, '')
out += image
process.stdout.write(out)
process.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment