{"id":13583299,"url":"https://github.com/nexdrew/rekcod","last_synced_at":"2025-04-05T04:08:56.495Z","repository":{"id":43753660,"uuid":"52889822","full_name":"nexdrew/rekcod","owner":"nexdrew","description":"docker inspect :mag: → docker run :runner:","archived":false,"fork":false,"pushed_at":"2021-07-15T10:25:49.000Z","size":122,"stargazers_count":377,"open_issues_count":12,"forks_count":33,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T19:42:31.346Z","etag":null,"topics":["docker","inspect","reverse","run"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nexdrew.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-01T15:58:57.000Z","updated_at":"2025-01-23T10:32:27.000Z","dependencies_parsed_at":"2022-07-10T21:03:01.795Z","dependency_job_id":null,"html_url":"https://github.com/nexdrew/rekcod","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexdrew%2Frekcod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexdrew%2Frekcod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexdrew%2Frekcod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexdrew%2Frekcod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nexdrew","download_url":"https://codeload.github.com/nexdrew/rekcod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284943,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","inspect","reverse","run"],"created_at":"2024-08-01T15:03:23.227Z","updated_at":"2025-04-05T04:08:56.459Z","avatar_url":"https://github.com/nexdrew.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ![rekcod](https://raw.githubusercontent.com/nexdrew/rekcod/master/logo.png)\n\n\u003e docker inspect → docker run\n\n[![Build Status](https://travis-ci.com/nexdrew/rekcod.svg?branch=master)](https://travis-ci.com/nexdrew/rekcod)\n[![Coverage Status](https://coveralls.io/repos/github/nexdrew/rekcod/badge.svg?branch=master)](https://coveralls.io/github/nexdrew/rekcod?branch=master)\n[![JavaScript Style Guide](https://badgen.net/badge/code%20style/standard/green)](https://standardjs.com)\n[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)\n![Dependabot Badge](https://badgen.net/dependabot/nexdrew/rekcod?icon=dependabot\u0026label=dependabot)\n[![Docker Pulls](https://badgen.net/docker/pulls/nexdrew/rekcod?icon=docker)](https://hub.docker.com/r/nexdrew/rekcod)\n[![Docker Image Size](https://badgen.net/docker/size/nexdrew/rekcod?icon=docker)](https://hub.docker.com/r/nexdrew/rekcod)\n\nReverse engineer a `docker run` command from an existing container (via `docker inspect`).\n\n`rekcod` can turn any of the following into a `docker run` command:\n\n1. container ids/names (`rekcod` will call `docker inspect`)\n2. path to file containing `docker inspect` output\n3. raw JSON (pass the `docker inspect` output directly)\n\nEach `docker run` command can be used to duplicate the containers.\n\nThis is not super robust, but it should cover most arguments needed. See [Fields Supported](#fields-supported) below.\n\nWhen passing container ids/names, this module calls `docker inspect` directly, and the user running it should be able to as well.\n\n(If you didn't notice, the dumb name for this package is just \"docker\" in reverse.)\n\n## Install and Usage\n\n### CLI\n\nIf you have Node installed:\n\n```\n$ npm i -g rekcod\n```\n\nIf you only have Docker installed:\n\n```\n$ docker pull nexdrew/rekcod\n$ alias rekcod=\"docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod\"\n```\n\nOr you can simply run this, no installation required:\n\n```\n$ docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod \u003ccontainer\u003e\n```\n\n#### Containers\n\n```sh\n# containers as arguments\n$ rekcod container-one 6653931e39f2 happy_torvalds\n\ndocker run --name container-one ...\n\ndocker run --name stinky_jones ...\n\ndocker run --name happy_torvalds ...\n```\n\n```sh\n# pipe in containers\n$ docker ps -aq | rekcod\n\ndocker run --name container-one ...\n\ndocker run --name stinky_jones ...\n\ndocker run --name happy_torvalds ...\n```\n\n#### Files\n\nIf 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:\n\n```sh\n# file names as arguments (Node CLI example)\n$ docker inspect container-one \u003e one.json\n$ docker inspect 6653931e39f2 happy_torvalds \u003e two.json\n$ rekcod one.json two.json\n\ndocker run --name container-one ...\n\ndocker run --name stinky_jones ...\n\ndocker run --name happy_torvalds ...\n```\n\n```sh\n# pipe in file names (Node CLI example)\n$ docker inspect container-one \u003e one.json\n$ docker inspect 6653931e39f2 happy_torvalds \u003e two.json\n$ ls *.json | rekcod\n```\n\nIf 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:\n\n```sh\n# file names as arguments (Docker-only example)\n$ docker inspect container-one \u003e one.json\n$ docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`/one.json:/one.json nexdrew/rekcod /one.json\n\ndocker run --name container-one ...\n```\n\nOtherwise, 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:\n\n```sh\n# pipe in file contents (works for Node CLI or Docker-only alias)\n$ cat one.json | rekcod\n```\n\n#### JSON\n\n```sh\n$ docker inspect container-one 6653931e39f2 | rekcod\n\ndocker run --name container-one ...\n\ndocker run --name stinky_jones ...\n```\n\n### Module\n\n```\n$ npm i --save rekcod\n```\n\n#### Containers via async `reckod()`\n\n```js\nconst rekcod = require('rekcod')\n// single container\nrekcod('container-name', (err, run) =\u003e {\n  if (err) return console.error(err)\n  console.log(run[0].command)\n})\n// multiple containers\nrekcod(['another-name', '6653931e39f2', 'happy_torvalds'], (err, run) =\u003e {\n  if (err) return console.error(err)\n  run.forEach((r) =\u003e {\n    console.log('\\n', r.command)\n  })\n})\n```\n\n#### File via async `rekcod.readFile()`\n\n```js\nconst rekcod = require('rekcod')\nrekcod.readFile('docker-inspect.json', (err, run) =\u003e {\n  if (err) return console.error(err)\n  run.forEach((r) =\u003e {\n    console.log('\\n', r.command)\n  })\n})\n```\n\n#### Parse a JSON string via sync `rekcod.parse()`\n\n```js\nconst fs = require('fs')\nconst rekcod = require('rekcod')\nlet array\ntry {\n  array = rekcod.parse(fs.readFileSync('docker-inspect.json', 'utf8'))\n} catch (err) {\n  return console.error(err)\n}\narray.forEach((r) =\u003e {\n  console.log('\\n', r.command)\n})\n```\n\n## Fields Supported\n\n`rekcod` will translate the following `docker inspect` fields into the listed `docker run` arguments.\n\n| docker inspect               | docker run       |\n| ---------------------------- | ---------------- |\n| `Name`                       | `--name`         |\n| `HostConfig.Privileged`      | `--privileged`   |\n| `HostConfig.Runtime`         | `--runtime`      |\n| `HostConfig.Binds`           | `-v`             |\n| `HostConfig.VolumesFrom`     | `--volumes-from` |\n| `HostConfig.PortBindings`    | `-p`             |\n| `HostConfig.Links`           | `--link`         |\n| `HostConfig.PublishAllPorts` | `-P`             |\n| `HostConfig.NetworkMode`     | `--net`          |\n| `HostConfig.UTSMode`         | `--uts`          |\n| `HostConfig.RestartPolicy`   | `--restart`      |\n| `HostConfig.ExtraHosts`      | `--add-host`     |\n| `HostConfig.GroupAdd`        | `--group-add`    |\n| `HostConfig.PidMode`         | `--pid`          |\n| `HostConfig.SecurityOpt`     | `--security-opt` |\n| `Config.Hostname`            | `-h`             |\n| `Config.Domainname`          | `--domainname`   |\n| `Config.ExposedPorts`        | `--expose`       |\n| `Config.Labels`              | `-l`             |\n| `Config.Env`                 | `-e`             |\n| `Config.Attach`* !== true    | `-d`             |\n| `Config.AttachStdin`         | `-a stdin`       |\n| `Config.AttachStdout`        | `-a stdout`      |\n| `Config.AttachStderr`        | `-a stderr`      |\n| `Config.Tty`                 | `-t`             |\n| `Config.OpenStdin`           | `-i`             |\n| `Config.Entrypoint`          | `--entrypoint`   |\n| `Config.Image` \u0026#124;\u0026#124; `Image` | image name or id |\n| `Config.Cmd`                 | command and args |\n\nPrior 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. ❤\n\n## License\n\nISC © Contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexdrew%2Frekcod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnexdrew%2Frekcod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexdrew%2Frekcod/lists"}