Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Created July 6, 2014 12:19
Show Gist options
  • Save miracle2k/c85b7b077fdb8d54bc89 to your computer and use it in GitHub Desktop.
Save miracle2k/c85b7b077fdb8d54bc89 to your computer and use it in GitHub Desktop.

Revisions

  1. miracle2k created this gist Jul 6, 2014.
    20 changes: 20 additions & 0 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Convert an existing docker container into a "docker run" command line.
    #
    # This is useful when trying to debug containers that have been created
    # by orchestration tools.
    #
    # Install jq: stedolan.github.io/jq/

    function format_run() {
    cid=$1

    json=$(docker inspect $cid 2>&1)

    # parse container info
    entrypoint=$( echo $json | jq -r '.[0].Config.Entrypoint | join(" ")' )
    envvars=$( echo $json | jq -r '(.[0].Config.Env | [" -e " + .[]] | join(""))' )
    image=$( echo $json | jq -r .[0].Image )
    cmd=$( echo $json | jq -r '.[0].Config.Cmd | join(" ")' )

    echo "docker run --entrypoint $entrypoint $envvars $image $cmd"
    }