GithubHelp home page GithubHelp logo

isabella232 / rekcod Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elastic/rekcod

0.0 0.0 0.0 143 KB

docker inspect :mag: → docker run :runner:

License: ISC License

JavaScript 99.36% Dockerfile 0.64%

rekcod's Introduction

rekcod

docker inspect → docker run

Build Status Coverage Status Standard Version Greenkeeper badge

Reverse engineer a docker run command from an existing container (via docker inspect).

rekcod can turn any of the following into a docker run command:

  1. container ids/names (rekcod will call docker inspect)
  2. path to file containing docker inspect output
  3. raw JSON (pass the docker inspect output directly)

Each docker run command can be used to duplicate the containers.

This is not super robust, but it should cover most arguments needed. See Fields Supported below.

When passing container ids/names, this module calls docker inspect directly, and the user running it should be able to as well.

(If you didn't notice, the dumb name for this package is just "docker" in reverse.)

Install and Usage

CLI

If you have Node installed:

$ npm i -g rekcod

If you only have Docker installed:

$ docker pull nexdrew/rekcod
$ alias rekcod="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod"

Or you can simply run this, no installation required:

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod <container>

Containers

# containers as arguments
$ rekcod container-one 6653931e39f2 happy_torvalds

docker run --name container-one ...

docker run --name stinky_jones ...

docker run --name happy_torvalds ...
# pipe in containers
$ docker ps -aq | rekcod

docker run --name container-one ...

docker run --name stinky_jones ...

docker run --name happy_torvalds ...

Files

# file names as arguments
$ docker inspect container-one > one.json
$ docker inspect 6653931e39f2 happy_torvalds > two.json
$ rekcod one.json two.json

docker run --name container-one ...

docker run --name stinky_jones ...

docker run --name happy_torvalds ...
# pipe in file names
$ docker inspect container-one > one.json
$ docker inspect 6653931e39f2 happy_torvalds > two.json
$ ls *.json | rekcod

JSON

$ docker inspect container-one 6653931e39f2 | rekcod

docker run --name container-one ...

docker run --name stinky_jones ...

Arguments

There are several arguments supported by rekcod.

Specify the image

You can replace the image in the docker run... line generated by rekcod:

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod -i <image> <container>

Specify additional environment variables

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod -e FOO=BAR <container>

Specify additional bind mounts

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod -v /src:/dst <container>

Module

$ npm i --save rekcod

Containers via async reckod()

const rekcod = require('rekcod')
// single container
rekcod('container-name', (err, run) => {
  if (err) return console.error(err)
  console.log(run[0].command)
})
// multiple containers
rekcod(['another-name', '6653931e39f2', 'happy_torvalds'], (err, run) => {
  if (err) return console.error(err)
  run.forEach((r) => {
    console.log('\n', r.command)
  })
})

File via async rekcod.readFile()

const rekcod = require('rekcod')
rekcod.readFile('docker-inspect.json', (err, run) => {
  if (err) return console.error(err)
  run.forEach((r) => {
    console.log('\n', r.command)
  })
})

Parse a JSON string via sync rekcod.parse()

const fs = require('fs')
const rekcod = require('rekcod')
let array
try {
  array = rekcod.parse(fs.readFileSync('docker-inspect.json', 'utf8'))
} catch (err) {
  return console.error(err)
}
array.forEach((r) => {
  console.log('\n', r.command)
})

Fields Supported

rekcod will translate the following docker inspect fields into the listed docker run arguments.

docker inspect docker run
Name --name
HostConfig.Binds -v
HostConfig.VolumesFrom --volumes-from
HostConfig.PortBindings -p
HostConfig.Links --link
HostConfig.PublishAllPorts -P
HostConfig.NetworkMode --net
HostConfig.RestartPolicy --restart
HostConfig.ExtraHosts --add-host
Config.Hostname -h
Config.ExposedPorts --expose
Config.Env -e
Config.Attach* !== true -d
Config.AttachStdin -a stdin
Config.AttachStdout -a stdout
Config.AttachStderr -a stderr
Config.Tty -t
Config.OpenStdin -i
Config.Entrypoint --entrypoint
Config.Image || Image image name or id
Config.Cmd command and args

Prior to version 0.2.0, rekcod always assumed -d for detached mode, but it now uses that only when all stdio options are not attached. I believe this is the correct behavior, but let me know if it causes you problems. A side effect of this is that the -d shows up much later in the docker run command than it used to, but it will still be there.

License

ISC © Contributors

rekcod's People

Contributors

greenkeeper[bot] avatar hasnat avatar mpv avatar nexdrew avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.