Created
February 9, 2016 23:09
-
-
Save tjmehta/33c87502956cb4cc56ee to your computer and use it in GitHub Desktop.
Publish all expose ports to 1-to-1 w/ docker host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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