GithubHelp home page GithubHelp logo

rekcod's Introduction

rekcod

docker inspect → docker run

Build Status Coverage Status JavaScript Style Guide Standard Version Dependabot Badge Docker Pulls Docker Image Size

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 -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod"

Or you can simply run this, no installation required:

$ docker run --rm -i -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

If you are using the Node CLI - i.e. you installed rekcod via npm or yarn - you can pass file names or file contents to rekcod as is, since the Node CLI will have access to files on the host file system:

# file names as arguments (Node CLI example)
$ 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 (Node CLI example)
$ docker inspect container-one > one.json
$ docker inspect 6653931e39f2 happy_torvalds > two.json
$ ls *.json | rekcod

If you are using the Docker-only version of rekcod - i.e. you are using docker run to run the nexdrew/rekcod image - then note that you'll need to bind mount files from the host file system as volumes on the rekcod container in order for the containerized executable to read them:

# file names as arguments (Docker-only example)
$ docker inspect container-one > one.json
$ docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`/one.json:/one.json nexdrew/rekcod /one.json

docker run --name container-one ...

Otherwise, as long as you read the file from the host system, you can pipe the contents of a file to rekcod and either installation method will work:

# pipe in file contents (works for Node CLI or Docker-only alias)
$ cat one.json | rekcod

JSON

$ docker inspect container-one 6653931e39f2 | rekcod

docker run --name container-one ...

docker run --name stinky_jones ...

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.Privileged --privileged
HostConfig.Runtime --runtime
HostConfig.Binds -v
HostConfig.VolumesFrom --volumes-from
HostConfig.PortBindings -p
HostConfig.Links --link
HostConfig.PublishAllPorts -P
HostConfig.NetworkMode --net
HostConfig.UTSMode --uts
HostConfig.RestartPolicy --restart
HostConfig.ExtraHosts --add-host
HostConfig.GroupAdd --group-add
HostConfig.PidMode --pid
HostConfig.SecurityOpt --security-opt
Config.Hostname -h
Config.Domainname --domainname
Config.ExposedPorts --expose
Config.Labels -l
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

dependabot-preview[bot] avatar greenkeeper[bot] avatar hasnat avatar hertzg avatar mpv avatar nexdrew avatar nin9s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rekcod's Issues

Support for CLI piping/redirection to rekcod

You can currently do docker ps -aq | xargs rekcod (just like you can with docker inspect), but it would be cool to support that without needing xargs.

Should detect if no args are given and instead read from stdin.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Support promise-based API

I'm ok with supporting both callbacks and promises (where a Promise is returned if a callback is not given), but using promises has the benefit of working with async/await in Babel or the future.

Add possibility to process inspect json file content from stdin

I had some troubles re running container that stopped on production
And i did have permissions to install you lib on prod server
Though i could get content of docker inspect command for stopped container
My proposal to be able to process this file locally
For emaple by rekcod < inspect.json command

Docker version completely locks terminal when run without parameters

alias rekcod='docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod'
[root@monster ~]# rekcod

It never comes back. Can't seem to disconnect it. Throwing a 'kill' at the spawned docker process doesn't work but 'kill -9' does. -h crashes to "SyntaxError: Unexpected token F in JSON at position 0 at JSON.parse ()"

too new API version

When I run the alias/docker command I get the following error message:
Error response from daemon: client version 1.40 is too new. Maximum supported API version is 1.39

Running on a Synology NAS. Sorry, quiet a noob...

ExtraHosts isn't converted to --add-host

Hi, this tool is execellent! But I find that ExtraHosts, which can be found in docker inspect <container_id>, isn't converted to --add-host in the output of rekcod.

No results returned

I installed rekcod on an Unbuntu server (14.04). rekcod seem to run OK but returns no result. Is there a debug mode or a log that can tell me why it is not working?

Comparison with runlike

It would be nice if the readme had a section comparing this tool with runlike.

At first glance they seem to do about the same thing.

An in-range update of standard-version is breaking the build 🚨

Version 4.3.0 of standard-version was just published.

Branch Build failing 🚨
Dependency standard-version
Current Version 4.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

standard-version is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • coverage/coveralls Coverage pending from Coveralls.io Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 8 commits.

  • 9a99607 chore(release): 4.3.0
  • 4fd3bc2 feat: do not update/commit files in .gitignore (#230)
  • c5e1ee2 feat: publish only if commit+push succeed (#229)
  • 45fcad5 feat(format-commit-message): support multiple %s in the message
  • b37bc66 test(format-commit-message): add failing test cases
  • 3fdd7fa fix: use the skip default value for skip cli arg (#211)
  • 709dae1 fix: recommend --tag prerelease for npm publish of prereleases (#196)
  • 958daf4 chore: add link to community slack (#202)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Mount with '--mount' is not supported.

$ docker run -d --name with-mount --rm --mount type=bind,source=/tmp,target=/my_tmp alpine sleep 100

$ rekcod with-mount

docker run --name with-mount --runtime runc --restart no -h 48d4cf4d05db -e 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -d alpine 'sleep' '100'





$ docker run -d --name with-v --rm -v/tmp:/my_tmp alpine sleep 100

$ rekcod with-v

docker run --name with-v --runtime runc -v /tmp:/my_tmp --restart no -h 90a795749a37 -e 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -d alpine 'sleep' '100'

Error: No such object: dockerinspect.json

When I send inspect output to a json file and then use rekcod, I get empty output and then it complains about no such object.

This is using the docker installation with an alias.

phillijw@computer:~$ ls *.json
dockerinspect.json
phillijw@computer:~$ rekcod dockerinspect.json
[]

Error: No such object: dockerinspect.json

phillijw@computer:~$

An in-range update of coveralls is breaking the build 🚨

The devDependency coveralls was updated from 3.0.5 to 3.0.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

--privileged not supported

I actually got to try out the tool. In addition to hitting #40, I noticed a problem with one of my containers not working because it relied on --privileged. Thought I'd let you know it's something I'm currently missing.

Podman support

Is it somehow possible to enable Podman support since the inspect output should be similar?
And is the mounted socket necessary if only the inspect JSON will be piped to rekcod?

Also create docker-compose.yml?

I love this project! Hadn't actually tried out the commands it generates yet, but if it works as expected it'll be a life-saver for me. I have a question though - would it be within the project's scope to also generate docker-compose.yml files? The use case is about being able to migrate small-scale Docker hosts by just dumping the configuration and running it on a different host.

getting: "exec format error"

When running this

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod something

the response is:

standard_init_linux.go:211: exec user process caused "exec format error"

Support for other runtimes [e.g. nvidia, kata]

I'm using the nvidia runtime for getting direct access to GPUs from inside a container. It's readable via docker inspect in the Runtime field:

[
  {
      ...
      "UTSMode": "",
      "UsernsMode": "",
      "ShmSize": 67108864,
      "Runtime": "nvidia",   <--
      "ConsoleSize": [
        0,
        0
      ],
      ...
  }
]

and should be transformed to docker run --runtime=nvidia ….

The same applies to kata container runtime.

conflicting options hostname and the network mode / sh -c not properly quoted

Thanks for the great tool!

Two minor problems:

  1. docker says Conflicting options: hostname and the network mode.
    when .HostConfig.NetworkMode == "host", and .Config.Hostname is set

  2. when .Config.Cmd is ["sh", "-c", "(a -a) \u0026\u0026 (b -b)"], generated command is sh -c (a -a) && (b -b), but it should be sh -c '(a -a) && (b -b)' (with quotes)

Support --volumes-from

Currently doesn't look for HostConfig.VolumesFrom in docker inspect output. This is an important missing factor. Let's fix it!

Passing files or piping stdin to the containerized version

The documentation suggests the following way to interpret a json file:

alias rekcod="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod"
rekcod one.json

There is also an undocumented way to pass stdin to the tool:

cat one.json | rekcod

Neither way works. However, if one changes

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

(note the -i flag) then cat one.json | rekcod works, while passing a filename requires the following construct:

docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock \
  -v `pwd`/one.json:/one.json nexdrew/rekcod /one.json

(i.e. mount the file into the container) The documentation could be clearer on this.

Doesn't retreive IP addresses

Using docker ( alias rekcod='docker run --name rekcod --rm -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod' ) on a container created by Portainer (likely not relevant?) it fails to recover specified IP addresses.

Obviously I've pruned the output here for privacy as much as I can be bothered, but I didn't remove any parameters (except volumes) and merely censored/changed network topology information.

[root@monster ~]# rekcod mediamanagers_tdarr-node_1
docker run --name mediamanagers_tdarr-node_1 --runtime nvidia -v /docker/media-managers/tdarr-node/configs:/app/configs:rw -v /docker/media-managers/tdarr-node:/app/logs:rw --net secondary_lan --restart unless-stopped -h 22d83964b657 --expose ---/tcp --expose ---/tcp --expose ---/tcp -l com.docker.compose.config-hash='210fa5c1e45a4b5085fa8026849f7b01fd867f7eb7f1deeab0b90f4bae27b555' -l com.docker.compose.container-number='1' -l com.docker.compose.oneoff='False' -l com.docker.compose.project='mediamanagers' -l com.docker.compose.project.config_files='/data/compose/4/docker-compose.yml' -l com.docker.compose.project.working_dir='/data/compose/4' -l com.docker.compose.service='tdarr-node' -l com.docker.compose.version='1.27.4' -e 'TZ=America/Los_Angeles' -e 'PUID=1006' -e 'PGID=100' -e 'GIDLIST=100,989,986' -e 'UMASK_SET=002' -e 'nodeID=---' -e 'nodeIP=---.---.---.---' -e 'nodePort=---' -e 'serverIP=---.---.---.---' -e 'serverPort=---' -e 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -e 'UMASK=002' -e 'PORT1=---' -e 'PORT2=---' -e 'LANGUAGE=en_US.UTF-8' -e 'LANG=' -e 'LC_ALL=' -e 'DEBIAN_FRONTEND=noninteractive' -e 'LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri/' -e 'LD_LIBRARY_PATH=/usr/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64' -e 'S6_REL=2.0.0.1' -e 'NODE_VERSION=14' -e 'NODE_PORT=---' -d --entrypoint "/init" haveagitgat/tdarr_node:latest

(While it's on my mind - is there a way we can "pretty-print" that with newlines via argument to rekcod? That would make life easier. I tried to run it with no parameters to check options and had to kill the docker PID to get my ssh terminal back. YIKES.)

There's clearly a lot of junk there created by the container and/or Portainer, but the relevant section of the Stack (Portainer's docker-compose wrapper thing) is such;

  tdarr-node:
    image: haveagitgat/tdarr_node:latest
    runtime: nvidia
    restart: unless-stopped
    networks:
      primary_lan:
        ipv4_address:  192.168.1.1
    environment:
      - TZ=America/Los_Angeles
      - PUID=1006
      - PGID=100
      - GIDLIST=100,989,986
      - UMASK_SET=002
      - nodeID=---
      - nodeIP=---.---.---.---
      - nodePort=--
      - serverIP=---.---.---.---
      - serverPort=--
    volumes:
      - /docker/media-managers/tdarr-node/configs:/app/configs
      - /docker/media-managers/tdarr-node:/app/logs

Importantly - the networks/<network_name>/ipv4_address tag is not being caught. Sorry for so much extra information, didn't want to overly prune it and invalidate the issue.

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.